How can I find the php.ini file used by the command line?
Just run php --ini
and look for Loaded Configuration File in the output for the location of php.ini
used by your CLI.
Where can I find php.ini?
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.
How can I know which 'php.ini' file is used?
You can use php_ini_loaded_file().
Taken from php.net:
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
You may also want to check php_ini_scanned_files().
Also, you should note that if you run a PHP script from CLI, it's possible that a different php.ini
file will be used than if a server (e.g., nginx or Apache) runs it.
Other options:
php -i|grep 'php.ini'
- create
info.php
that contains<?php phpinfo();
in the webroot, and run it in your browser
where can I find the php.ini for php-cli
Just ask PHP:
php -i |grep php\.ini
Where is the php.ini file on a Linux/CentOS PC?
In your terminal/console (only Linux, in windows you need Putty)
ssh user@ip
php -i | grep "Loaded Configuration File"
And it will show you something like this Loaded Configuration File => /etc/php.ini
.
ALTERNATIVE METHOD
You can make a php file on your website, which run: <?php phpinfo(); ?>
, and you can see the php.ini location on the line with: "Loaded Configuration File".
Update
This command gives the path right away
cli_php_ini=php -i | grep /.+/php.ini -oE #ref. https://stackoverflow.com/a/15763333/248616
php_ini="${cli_php_ini/cli/apache2}" #replace cli by apache2 ref. https://stackoverflow.com/a/13210909/248616
PHP Command Line php.ini path error
Using the -c
option, you can specify which php.ini
file should be used :
php -c /etc/php.ini your-php-script.php
As a reference, see the output of php --help
:
$ php --help
Usage: php [options] [-f] <file> [--] [args...]
php [options] -r <code> [--] [args...]
php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]
php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]
php [options] -- [args...]
php [options] -a
-a Run as interactive shell
-c <path>|<file> Look for php.ini file in this directory
-n No php.ini file will be used
-d foo[=bar] Define INI entry foo with value 'bar'
...
Related Topics
How to Convert a String to a Number in PHP
How to Measure the Speed of Code Written in PHP
Streaming a Large File Using PHP
PHP Exec Command (Or Similar) to Not Wait For Result
How to Have a 64-Bit Integer in PHP
How to Return Outer HTML of Domdocument
Preparing For Removal of Mcrypt in PHP 7.2
Correct File Permissions For Wordpress
Show Values from a MySQL Database Table Inside a HTML Table on a Webpage
Get Value from Simplexmlelement Object
How to Set HTML Value Attribute (With Spaces)
How to Push Both Value and Key into PHP Array
How to Remove Accents and Turn Letters into "Plain" Ascii Characters