2

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!

1
  • When testing with the CLI, did you use the user Apache is running under ? could be a permission problem.
    – b0fh
    Jul 3, 2012 at 9:10

2 Answers 2

1

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.).

0

Assuming that webserver PHP is running as mod_php, the 2 most likely causes are:

1) the permissions on the php.ini file or the .so file do not allow the webserver uid access to the file(s)

2) the webserver is running chroot

You can easily test this from PHP using 'is_readable' and, in the case of php.ini use file_get_contents() to check the file contains what you expect, and in the case of mysql.so, use dl() to load the file.

1
  • I can get the contents of all configuration files, but the dl() function seems to be deprecated and gives me a warning (PHP Warning: dl(): Dynamically loaded extensions aren't enabled) in php5-cli, and an error on apache: Fatal error: Call to undefined function dl()
    – Víctor
    Jul 3, 2012 at 13:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .