2个php.ini文件 [英] 2 php.ini files
问题描述
我发现:
当我在终端上键入以下内容时:
When I type the following on terminal:
php -i | grep php.ini
我得到输出:
已加载的配置文件为@/etc/php5/cli/php.ini
The Loaded Configuration file is @ /etc/php5/cli/php.ini
但是,从phpinfo()
,我可以看到:
However, from phpinfo()
, I get to see:
已加载的ini文件为@/etc/php5/apache2/php.ini
The loaded ini file is @ /etc/php5/apache2/php.ini
其中哪一个现在正在工作?怎么有两个php.ini
文件?
Which one of these is working right now? How is it possible to have two php.ini
files ?
推荐答案
取决于您从何处运行PHP.如果从命令行运行它,则在通过apache运行时会使用cli/php.ini
和apache2/php.ini
.
Depends on where you are running PHP from. If you run it from command line, it uses the cli/php.ini
and apache2/php.ini
when run through apache.
您正在通过浏览器执行phpinfo()
,因此得到/etc/php5/apache2/php.ini
作为答案.从终端运行php -r "phpinfo();" | grep "Loaded Configuration"
应该会输出CLI ini.功能相同,上下文会发生变化.
You are executing phpinfo()
through the browser, hence you get /etc/php5/apache2/php.ini
as the answer. Running php -r "phpinfo();" | grep "Loaded Configuration"
from the terminal should output the CLI ini. Same function, context changes.
该系统的优势显然是允许根据上下文进行不同的配置.对于一个简化的示例,您可能希望在apache中打开safe_mode
,但是在CLI模式下则不需要.
The advantage of this system is obviously to allow different configurations depending on the context. For a simplified example, you might want to have safe_mode
on in apache but it's unnecessary in CLI mode.
您的.ini
路径实际上很不寻常.通常,默认.ini仅为php.ini
,CLI .ini被称为php-cli.ini
,它们位于同一文件夹中.
Your .ini
paths are actually quite unusual. Normally, the default .ini is just php.ini
and CLI .ini is called php-cli.ini
and they reside in the same folder.
我不是该主题的专家,但这应该是基本思想.如果有人有任何更正,我很乐意听到.
I'm no expert on the subject but this should be the basic idea. If anyone has any corrections, I'd be happy to hear them.
这篇关于2个php.ini文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!