Php.Ini: Which One

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

Who reads the 'php.ini' file and how many php.ini files can possibly be exist there? What's the role of every such 'php.ini' file?

  1. The PHP compiler/parser.
  2. Because PHP does not persist for command line invocations, so it is read at run-time.
  3. Every time you call a PHP script, either CGI or CLI.
  4. More than one, typically 2. One for the web server and one for CLI/CGI.

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.

How is php.ini related to php.ini-development and php.ini-production?

They are template files for you to copy over to your actual php.ini if you feel it matches your environment's needs.

  • Development environment offers verbose messages and comfortable optional features, what you want when you're coding your scripts.
  • Production environment is typically more minimalist (i.e. errors are logged rather than displayed, etc), for interacting with real users efficiently.


Related Topics



Leave a reply



Submit