如何知道使用的是哪个 php.ini?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14558150/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:31:53  来源:igfitidea点击:

How to know which php.ini is used?

phpphp-ini

提问by pheromix

I search the path where the php.ini file is located in our Linux Ubuntu server, and I found many php.ini when executing the command find / -name php.ini. So how to know exactly from a php script web page where the php.ini is located ?

我在我们的Linux Ubuntu服务器中搜索php.ini文件所在的路径,在执行命令时发现了很多php.ini find / -name php.ini。那么如何从 php 脚本网页中准确地知道 php.ini 所在的位置呢?

回答by KingCrunch

php --ini

For the webserver-SAPIs use phpinfo()

对于 webserver-SAPIs 使用 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

回答by Vlad Preda

You can use php_ini_loaded_file()

您可以使用php_ini_loaded_file()

Taken from php.net:

摘自 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()

您可能还想检查php_ini_scanned_files()

Also, you should note that if you run a PHP script from CLI, it's possible that a different php.inifile will be used than if a server (ie nginx or apache) runs it.

另外,您应该注意,如果您从 CLI 运行 PHP 脚本,则可能php.ini会使用与服务器(即 nginx 或 apache)运行它不同的文件。

Other options:

其他选项:

  • php -i|grep 'php.ini'
  • create info.phpthat contains <?php phpinfo();in the webroot, and run it in your browser
  • php -i|grep 'php.ini'
  • 创建info.php包含<?php phpinfo();在 webroot 中的文件,并在浏览器中运行它

回答by 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.

请注意,在控制台上使用 PHP 时为 PHP 加载的配置与 Web 进程的配置不同。大多数 PHP 安装都会附带一个用于 apache 的 php.ini 和另一个用于 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

要了解 Web 进程使用哪个配置文件,请按照下列步骤操作

  1. Create an info file [preferably in the root folder]
  2. The contents of this file should be <?php phpinfo(); ?>
  3. Ctrl+Fand search for "Configuration File"
  1. 创建一个信息文件[最好在根文件夹中]
  2. 这个文件的内容应该是 <?php phpinfo(); ?>
  3. Ctrl+F并搜索“配置文件”

回答by darkheir

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

你必须使用php方法php_ini_loaded_file(只有在php 5.2.4之后)

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

php_ini_loaded_file — 检索加载的 php.ini 文件的路径

php website example:

php网站示例:

<?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

来源:php网站

回答by Vahid Farahmand

just put a file like this:

只需放一个这样的文件:

<?php
phpinfo();
?>

Then look for

然后寻找

Loaded Configuration File

you'll see full path for php.ini file

你会看到 php.ini 文件的完整路径

回答by Lee Armstrong

Create a simple page and it will be listed there!

创建一个简单的页面,它将在那里列出!

<?php

phpinfo();

?>

回答by Jayanta Deka

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.

如前所述,“find / -name php.ini”将有助于获取所有 php.ini 文件。您可能正在编辑的那个可能不是服务器从中提取命令的那个!我在我的服务器上找到了 3 个不同版本的 php 的 php.ini,然后我立即得到了修复。