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.
March 27th, 2006 at 11:33 am
Very handy. Thanks for pointing it out.
May 18th, 2007 at 10:14 am
Thank you the article.
I only know where the php.ini file in windows,Now I know more..
September 27th, 2007 at 11:00 am
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
March 3rd, 2008 at 12:59 am
jimsotonna…
jimsotonna dropped by…
April 5th, 2008 at 12:46 am
This is an amazing tip…thank you sooo much.
August 12th, 2008 at 10:32 am
Thanks for the article…Could you also tell us how to increase the time limit on the execution in the .ini file ? Thanks