php.ini is not getting read
Solution 1
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.
Solution 2
As a workaround you can use PHPIniDir directive in Apache Configuration to force PHP to a use a particular php.ini file
<IfModule mod_php5.c>
PHPIniDir "usr/local/lib"
</IfModule>
Now that should force PHP to use your php.ini file.
Related videos on Youtube
Tony
Updated on September 17, 2022Comments
-
Tony over 1 year
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.
-
crb almost 15 yearsCan you please paste the relevant output from phpinfo()?
-
msanford almost 15 yearsWhere/when did you configure php to look in /etc/php5/apache2? When you compiled it?
-
Tony almost 15 yearsi added more information to the question
-
-
Tony almost 15 yearssounds like a good option but i don't have strace. maybe because i am on ubuntu?
-
msanford almost 15 yearsI don't mean to be trite, but do you in fact have a /etc/apache2/apache2.conf file? Is it readable and does it contain all the necessary directives?
-
EricMinick almost 15 years"sudo aptitude install strace"
-
Tony almost 15 yearsno... thanks for helping! i don't have an apache2.conf because when i run "sudo apachectl graceful" it doesn't look for one and it doesn't need one. it looks at /etc/apache2/httpd.conf. im not sure why restarting it your way screws it up, although i would imagine starting apache your way wouldn't read /etc/apache2/httpd.conf which i don't like
-
Tony almost 15 yearsgood call, same problem as the answerer below you though. cant find apache2.conf. i think when i run "sudo apachectl graceful" it looks for different .conf's than "/usr/sbin/apache2 -k start." i guess it's possible they reference 2 different apache installations...not really sure what to do about that
-
David Pashley almost 15 yearsWell run strace -efile -f -o /tmp/apache.log apachectl start" instead
-
Tony almost 15 yearspermissions aren't the issue here. php is looking in the wrong place for the .ini
-
Tony almost 15 yearsi tried that with graceful and it didn't work, but worked with the start command. thanks for the great tip. unfortunately, as i suspected, php is looking in the wrong place for the .ini file. specifically "/usr/local/lib/". when i put php.ini in there, it works fine, and that will be my workaround for now. but again, seems odd that it is not looking in /etc/php5/apache2 after compiling it with those options. thanks again for the strace tip.
-
Fractaliste over 9 yearsIt works but don't explain why my file is not loaded with basic configuration :/