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.

  • 1
    Can you please paste the relevant output from phpinfo()?
    – crb
    Jul 4, 2009 at 0:50
  • Where/when did you configure php to look in /etc/php5/apache2? When you compiled it?
    – msanford
    Jul 4, 2009 at 1:02
  • 1
    i added more information to the question
    – Tony
    Jul 4, 2009 at 1:52

5 Answers 5


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.

  • sounds like a good option but i don't have strace. maybe because i am on ubuntu?
    – Tony
    Jul 4, 2009 at 1:56
  • "sudo aptitude install strace" Jul 4, 2009 at 2:44
  • good 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
    – Tony
    Jul 4, 2009 at 2:52
  • Well run strace -efile -f -o /tmp/apache.log apachectl start" instead Jul 4, 2009 at 3:33
  • i 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.
    – Tony
    Jul 4, 2009 at 7:31

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"

Now that should force PHP to use your php.ini file.

  • It works but don't explain why my file is not loaded with basic configuration :/ Dec 10, 2014 at 9:29

Did you restart apache after you changed the php.ini?

If you did, on some operating systems it seems that apache will cache the data so instead of doing /etc/init.d/apache reload you will need to do either /etc/init.d/apache restart or /etc/init.d/apache force-reload

  • yes i restarted apache. trying your method caused an error... "apache2: Could not open configuration file /etc/apache2/apache2.conf: No such file or directory ...fail!", seems to be looking for the wrong conf. i use "apachectl graceful"
    – Tony
    Jul 4, 2009 at 1:49
  • I 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?
    – msanford
    Jul 4, 2009 at 2:18
  • no... 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
    Jul 4, 2009 at 2:49

The directories /etc have /etc/php5 should execute permission for other. That is,

chmod o+x /etc /etc/php5

If directory /etc/php5/apache2 has either user or group owner as apache. Then atleast one of group or user should have read and execute permission on /etc/php5/apache2. Or simple give others read and execute permission on directory /etc/php5/apache2. That is,

chmod o+rx /etc/php5/apache2

Last do not make php.ini 777. That could cause problem if apache is checking for security permissions on file to make sure it is not world writable. Use 755 on php.ini. That is more than enough to ensure that the problem is not due to access control.

Similarly apache should be able to read other ini files as well. They other ini files should have read permission for others or they should belong to user/group apache and user/group read permissions are set.

  • permissions aren't the issue here. php is looking in the wrong place for the .ini
    – Tony
    Jul 4, 2009 at 7:27

After some time with the same problem, I realized that even tho I recompiled the PHP with the correct paths to load the configuration, I forgot to do a make clean before recompiling. Apparently it does not regenerate the specific part on php.ini load path unless you clean the object files.

After cleaning the build and recompiling, everything went well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.