How to know which php.ini is used?

一世执手 提交于 2019-11-27 11:39:18

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 (ie 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
KingCrunch
php --ini

For the webserver-SAPIs use phpinfo()

Here's some sample output:

bash-3.2# php --ini
Configuration File (php.ini) Path: /usr/local/php5/lib
Loaded Configuration File:         /usr/local/php5/lib/php.ini
Scan for additional .ini files in: /usr/local/php5/php.d
Additional .ini files parsed:      /usr/local/php5/php.d/10-extension_dir.ini,
/usr/local/php5/php.d/20-extension-opcache.ini,
/usr/local/php5/php.d/40-openssl.ini,
/usr/local/php5/php.d/50-extension-apcu.ini,
/usr/local/php5/php.d/50-extension-curl.ini,
/usr/local/php5/php.d/50-extension-gmp.ini,
/usr/local/php5/php.d/50-extension-imap.ini,
/usr/local/php5/php.d/50-extension-intl.ini,
/usr/local/php5/php.d/50-extension-mcrypt.ini,
/usr/local/php5/php.d/50-extension-mssql.ini,
/usr/local/php5/php.d/50-extension-pdo_pgsql.ini,
/usr/local/php5/php.d/50-extension-pgsql.ini,
/usr/local/php5/php.d/50-extension-propro.ini,
/usr/local/php5/php.d/50-extension-raphf.ini,
/usr/local/php5/php.d/50-extension-readline.ini,
/usr/local/php5/php.d/50-extension-xdebug.ini,
/usr/local/php5/php.d/50-extension-xsl.ini,
/usr/local/php5/php.d/60-extension-pecl_http.ini,
/usr/local/php5/php.d/99-liip-developer.ini
iGbanam

Note that the configuration loaded for PHP when it's being used on the console is different from the configuration for the web process. Most PHP installations would come with a php.ini for apache and another for CLI.

To know which configuration file is used for the console commands, use

$ php -i | grep "Configuration File"

To know which configuration file is used for the web processes, follow these steps

  1. Create an info file [preferably in the root folder]
  2. The contents of this file should be <?php phpinfo(); ?>
  3. Ctrl+F and search for "Configuration File"

You have to use the php method php_ini_loaded_file (only after php 5.2.4)

php_ini_loaded_file — Retrieve a path to the loaded php.ini file

php website example:

<?php
$inipath = php_ini_loaded_file();

if ($inipath) {
    echo 'Loaded php.ini: ' . $inipath;
} else {
    echo 'A php.ini file is not loaded';
}
?>

Source: php site

just put a file like this:

<?php
phpinfo();
?>

Then look for

Loaded Configuration File

you'll see full path for php.ini file

Create a simple page and it will be listed there!

<?php

phpinfo();

?>

As mentioned, "find / -name php.ini" will help get all the php.ini files. The one you may be editing may not be the one from which the server is drawing the command from! I found php.ini for 3 different versions of php on my server and I got the fix instantly then.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!