Php.ini is not getting read

configurationinstallationPHP

I configured PHP to look in /etc/php5/apache2 for the php.ini file. the output of phpinfo() says that the path was set correctly, but also says no configuration file was loaded. i changed the php.ini permissions to 777 temporarily to test that issue and permissions are not the issue. what else could the issue be?

When I compiled php, i did:

sudo ./configure --with-apxs2=/usr/sbin/apxs --with-mysql --enable-so --with-config-file-path=/etc/php5/apache2 --sysconfdir=/etc/php5 --with-config-file-scan-dir=/etc/php5/conf.d

phpinfo() says:

Configuration File (php.ini) Path           /etc/php5/apache2 
Loaded Configuration File                   (none)
Scan this dir for additional .ini files     (none) 
Additional .ini files parsed                (none) 

Also php –ini says:
Configuration File (php.ini) Path: /usr/local/lib
Loaded Configuration File: /etc/php5/apache2/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)

And if I put php.ini in /usr/local/lib, the configuration file loads fine (although the additional .ini files don't load). I am not sure why this is happening since I set the options when I compiled PHP.

Best Answer

The nuclear option is to run apache under strace, to see what it's doing when it tries to read the php.ini file.

Run "ps aux" to find the command line for apache, then stop the process. Now run:

# strace -efile -f -o /tmp/apache.log /usr/sbin/apache2 -k start

Request your phpinfo() page in a browser, and then kill the strace using ctrl-c. You can now grep /tmp/apache.log for php.ini and see if there are any errors displayed when it tries to read that file. This will show you problems like the file not being found or permission problems.

If there is an open() call that returns a number, then it would appear that it's reading the file in correctly, and there must be a problem with the file that's preventing php from parsing it correctly, but I'd expect this to be logged in the error log.