PHP Tip #1: Finding your php.ini file

If you’ve installed PHP in /usr/local as many people do, then your php.ini file is in /usr/local/php/lib. If you’ve installed PHP somewhere else, then you’ll find it in the corresponding lib directory. For instance, I like to put PHP in /opt/php5, so my php.ini file is in /opt/php5/lib.

There are a few other places it may be depending on platform. For instance, on Windows the Registry key HKEY_LOCAL_MACHINE\SOFTWARE\PHP\IniFilePath may contain a non-default location. On Unix the PHPRC environment variable can point to a non-default location. (However remember this is an environment variable for whatever user the web server runs as, likely not the same as your personal user account’s environment variables.)

You can use the locate command on most Unix’s or the Finder’s File/Find… on Mac OS X to look for it. However the most reliable way to locate it is to use the phpinfo() function from within a PHP page. Just place the following script in an info.phtml file somewhere on your web server, and load it in your browser:

<?php
phpinfo();
?>

Nothing else needs to be in this file. These three lines are enough. The file name doesn’t matter as long as it’s recognized as a PHP file.

About the sixth row of information dumped is “Configuration File (php.ini) Path” and this should tell you exactly where to look.

You may not actually see it in in any of these directories, including the one where PHP says it is. If so, you probably don’t have one. php.ini is not installed by default. You can create one in that directory using any text editor, though you may have to be root or use sudo to do so.

6 Responses to “PHP Tip #1: Finding your php.ini file”

  1. George Bailey Says:

    Very handy. Thanks for pointing it out.

  2. freemori Says:

    Thank you the article.
    I only know where the php.ini file in windows,Now I know more..

  3. Bala Krishna Says:

    Is there a way that i can change default location of php ini file from windows diectory other directory like c:\php .. I have installed both apache and IIS on same machine sharing same ini file from windows directory. I want to change location for IIS and as it is for apache.

    Many Thanks

  4. jimsotonna Says:

    jimsotonna…

    jimsotonna dropped by…

  5. Eva Says:

    This is an amazing tip…thank you sooo much.

  6. SVA Search Says:

    Thanks for the article…Could you also tell us how to increase the time limit on the execution in the .ini file ? Thanks

Leave a Reply