Where can I find php.ini?
On the command line execute:
php --ini
You will get something like:
Configuration File (php.ini) Path: /etc/php5/cli
Loaded Configuration File: /etc/php5/cli/php.ini
Scan for additional .ini files in: /etc/php5/cli/conf.d
Additional .ini files parsed: /etc/php5/cli/conf.d/curl.ini,
/etc/php5/cli/conf.d/pdo.ini,
/etc/php5/cli/conf.d/pdo_sqlite.ini,
/etc/php5/cli/conf.d/sqlite.ini,
/etc/php5/cli/conf.d/sqlite3.ini,
/etc/php5/cli/conf.d/xdebug.ini,
/etc/php5/cli/conf.d/xsl.ini
That's from my local dev-machine. However, the second line is the interesting one. If there is nothing mentioned, have a look at the first one. That is the path, where PHP looks for the php.ini
file.
You can grep the same information using phpinfo() in a script and call it with a browser. It’s mentioned in the first block of the output. php -i
does the same for the command line, but it’s quite uncomfortable.
The best way to find this is:
Create a PHP (.php) file and add the following code:
<?php phpinfo(); ?>
and open it in a browser. It will show the file which is actually being read!
Updates by the OP:
- The previously accepted answer is likely to be faster and more convenient for you, but it is not always correct. See comments on that answer.
- Please also note the more convenient alternative
<?php echo php_ini_loaded_file(); ?>
mentioned in this answer.