2个php.ini文件
我发现:
当我在终端上输入以下内容时:
php -i | grep php.ini
我得到输出:
加载的配置文件是@ /etc/php5/cli/php.ini
但是,从 phpinfo() 中,我看到:
加载的ini文件为@ /etc/php5/apache2/php.ini
其中哪一个现在正在工作?怎么可能有两个 php.ini 文件?
I have found that:
When I type the following on terminal:
php -i | grep php.ini
I get the output:
The Loaded Configuration file is @ /etc/php5/cli/php.ini
However, from phpinfo()
, I get to see:
The loaded ini file is @ /etc/php5/apache2/php.ini
Which one of these is working right now? How is it possible to have two php.ini
files ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
取决于您从何处运行 PHP。如果从命令行运行它,则在通过 apache 运行时它会使用
cli/php.ini
和apache2/php.ini
。您正在通过浏览器执行
phpinfo()
,因此您将得到/etc/php5/apache2/php.ini
作为答案。运行 php -r "phpinfo();" |终端中的 grep "Loaded Configuration" 应输出 CLI ini。相同的功能,上下文发生变化。该系统的优点显然是允许根据上下文进行不同的配置。作为一个简化的示例,您可能希望在 apache 中启用
safe_mode
,但在 CLI 模式下则没有必要。您的
.ini
路径实际上很不寻常。通常,默认的 .ini 只是php.ini
,CLI .ini 称为php-cli.ini
并且它们驻留在同一文件夹中。我不是这个主题的专家,但这应该是基本想法。如果有人有任何更正,我很乐意听到。
Depends on where you are running PHP from. If you run it from command line, it uses the
cli/php.ini
andapache2/php.ini
when run through apache.You are executing
phpinfo()
through the browser, hence you get/etc/php5/apache2/php.ini
as the answer. Runningphp -r "phpinfo();" | grep "Loaded Configuration"
from the terminal should output the CLI ini. Same function, context changes.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.Your
.ini
paths are actually quite unusual. Normally, the default .ini is justphp.ini
and CLI .ini is calledphp-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.