MySQL extension of PHP not working

apache-2.2debianMySQLPHP

In a Debian server, and after intallation and removal of SquirrelMail (with some downgrade and upgrade of php5, mysql…) the MySQL extension of PHP has stopped working.

I have php5-mysql installed, and when I try to connect to a database through php-cli, i connect successfully, but when I try to connect from a web served by Apache I cannot connect.

This script, run by php5-cli:

echo phpinfo();
$link = mysql_connect('localhost', 'user, 'password');
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }
echo 'Connected successfully';
mysql_close($link);

Prints the phpinfo, which includes "/etc/php5/cli/conf.d/mysql.ini", and also the MySQL section with all the configuration: SOCKET, LIBS… And then it prints "Connectes successfully".

But when run by apache accessed by web browser, it displays the phpinfo, which includes "/etc/php5/apache2/conf.d/mysql.ini", but has the MySQL section missing, and the script dies printing "Fatal error: Call to undefined function mysql_connect()".

Note that both "/etc/php5/cli/conf.d/mysql.ini" and "/etc/php5/apache2/conf.d/mysql.ini" are in fact the same configuration, because I have in debian the structure:

/etc/php5/apache2
/etc/php5/cgi
/etc/php5/cli
/etc/php5/conf.d

And both point at the same directory:

/etc/php5/apache2/conf.d -> ../conf.d
/etc/php5/cli -> ../conf.d

Where /etc/php5/conf.d/mysql.ini consists of one line:

extension=mysql.so

So my question is: why is the MySQL extension for PHP not working if I have the configuration included just in the same way as in php-cli, which is working?

Thanks a lot!

Best Answer

This probably isn't a configuration issue. I'm not familiar with how things are done in Debian (regarding upgrading/downgrading PHP) but it seems the PHP used by Apache and the PHP CLI are in fact using different PHPs.

You can verify this by doing a phpinfo() from browser and a php -i on the commandline. If Apache and CLI are using the same PHP, the results should be exactly the same (same configure options, compile time, libraries enabled, etc.).

Related Topic