php ini-如何知道使用哪个php.ini?
我在Linux Ubuntu服务器中搜索php.ini文件所在的路径,并且在执行命令find / -name php.ini时发现很多php.ini。 那么如何从php.ini所在的php脚本网页中确切地知道呢?
pheromix asked 2020-02-02T05:41:57Z
7个解决方案
75 votes
php --ini
对于Web服务器SAPI使用phpinfo()
这是一些示例输出:
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
KingCrunch answered 2020-02-02T05:43:02Z
55 votes
您可以使用php_ini_loaded_file()
取自php.net:
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
您可能还需要检查php_ini_scanned_files()
另外,您应该注意,如果从CLI运行PHP脚本,则可能使用与服务器(即nginx或apache)运行不同的info.php文件。
其他选项:
info.php
创建info.php(在webroot中包含<?php phpinfo();),然后在浏览器中运行
Vlad Preda answered 2020-02-02T05:42:38Z
10 votes
请注意,在控制台上使用PHP时为PHP加载的配置与Web流程的配置不同。 大多数PHP安装都带有一个用于apache的php.ini和一个用于CLI的文件。
要知道哪个配置文件用于控制台命令,请使用
$ php -i | grep "Configuration File"
若要知道哪个配置文件用于Web进程,请按照下列步骤
创建一个信息文件(最好在根文件夹中)
该文件的内容应为Ctrl+F
Ctrl+F并搜索“配置文件”
iGbanam answered 2020-02-02T05:43:45Z
5 votes
您必须使用php方法php_ini_loaded_file(仅在php 5.2.4之后)
php_ini_loaded_file —检索已加载的php.ini文件的路径
php网站示例:
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
?>
资料来源:php网站
darkheir answered 2020-02-02T05:44:18Z
3 votes
只需放入一个这样的文件:
phpinfo();
?>
然后寻找
Loaded Configuration File
您将看到php.ini文件的完整路径
Vahid Farahmand answered 2020-02-02T05:44:47Z
2 votes
创建一个简单的页面,它将在此处列出!
phpinfo();
?>
Lee Armstrong answered 2020-02-02T05:45:06Z
0 votes
如前所述,“查找/ -name php.ini”将帮助获取所有php.ini文件。 您可能正在编辑的那个可能不是服务器从中绘制命令的那个! 我在服务器上找到了3个不同版本的php.ini的php.ini,然后立即获得了修复。
Jayanta Deka answered 2020-02-02T05:45:27Z