php.ini:哪个?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10665783/
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
php.ini: which one?
提问by HappyDeveloper
I moved from my old apache to nginx and php 5.3.10. And when I tried to modify php.ini to suit my needs, I found there are 3 of them:
我从我的旧 apache 转移到 nginx 和 php 5.3.10。当我尝试修改 php.ini 以满足我的需要时,我发现其中有 3 个:
$ locate php.ini
/etc/php5/cgi/php.ini
/etc/php5/cli/php.ini
/etc/php5/fpm/php.ini
Which one should I edit?
我应该编辑哪一个?
回答by Pascal MARTIN
Generally speaking, the cli/php.inifile is used when the PHP binary is called from the command-line.
You can check that running php --inifrom the command-line.
一般来说,cli/php.ini从命令行调用 PHP 二进制文件时会使用该文件。
您可以检查php --ini从命令行运行。
fpm/php.iniwill be used when PHP is run as FPM -- which is the case with an nginx installation.
And you can check that calling phpinfo()from a php page served by your webserver.
fpm/php.ini将在 PHP 作为 FPM 运行时使用——这是 nginx 安装的情况。
您可以检查phpinfo()来自您的网络服务器提供的 php 页面的调用。
cgi/php.ini, in your situation, will most likely not be used.
cgi/php.ini,在您的情况下,很可能不会使用。
Using two distinct php.inifiles (one for CLI, and the other one to serve pages from your webserver)is done quite often, and has one main advantages : it allows you to have different configuration values in each case.
经常
使用两个不同的php.ini文件(一个用于 CLI,另一个用于从您的网络服务器提供页面),并且有一个主要优点:它允许您在每种情况下使用不同的配置值。
Typically, in the php.inifile that's used by the web-server, you'll specify a rather short max_execution_time: web pages should be served fast, and if a page needs more than a few dozen seconds (30 seconds, by default), it's probably because of a bug -- and the page's generation should be stopped.
On the other hand, you can have pretty long scripts launched from your crontab (or by hand), which means the php.inifile that will be used is the one in cli/. For those scripts, you'll specify a much longer max_execution_timein cli/php.inithan you did in fpm/php.ini.
通常,在php.iniweb 服务器使用的文件中,您将指定一个相当短的max_execution_time: 网页应该快速提供,如果一个页面需要超过几十秒(默认为 30 秒),这可能是因为一个错误——页面的生成应该停止。
另一方面,您可以从 crontab(或手动)启动相当长的脚本,这意味着php.ini将使用的文件是cli/. 对于这些脚本,你会指定一个更长max_execution_time的cli/php.ini比你做的fpm/php.ini。
max_execution_timeis a common example ; you could do the same with several other configuration directives, of course.
max_execution_time是一个常见的例子;当然,你可以对其他几个配置指令做同样的事情。
回答by Sabe Barker
Although Pascal's answer was detailed and informative it failed to mention some key information in the assumption that everyone knows how to use phpinfo()
尽管 Pascal 的回答很详细且内容丰富,但在假设每个人都知道如何使用的情况下没有提及一些关键信息 phpinfo()
For those that don't:
对于那些没有:
Navigate to your webservers root folder such as /var/www/
导航到您的网络服务器根文件夹,例如 /var/www/
Within this folder create a text file called info.php
在此文件夹中创建一个名为的文本文件 info.php
Edit the file and type phpinfo()
编辑文件并输入 phpinfo()
Navigate to the file such as: http://www.example.com/info.php
导航到文件,例如: http://www.example.com/info.php
Here you will see the php.inipath under Loaded Configuration File:
在这里,您将看到以下php.ini路径Loaded Configuration File:
Make sure you delete info.phpwhen you are done.
确保info.php完成后删除。
回答by Antwan van Houdt
It really depends on the situation, for me its in fpm as I'm using PHP5-FPM. A solution to your problem could be a universal php.ini and then using a symbolic link created like:
这真的取决于情况,对我来说,它在 fpm 中,因为我使用的是 PHP5-FPM。您的问题的解决方案可能是通用 php.ini,然后使用创建的符号链接,如:
ln -s /etc/php5/php.ini php.ini
Then any modifications you make will be in one general .ini file. This is probably not really the best solution though, you might want to look into modifying some configuration so that you literally use one file, on one location. Not multiple locations hacked together.
然后,您所做的任何修改都将保存在一个通用 .ini 文件中。不过,这可能并不是最好的解决方案,您可能需要考虑修改一些配置,以便在一个位置上真正使用一个文件。没有多个地点被黑客攻击在一起。
回答by Fr4NgUs
You can find what is the php.ini file used:
您可以找到使用的 php.ini 文件:
- By add phpinfo()in a php page and display the page (like the picture under)
- From the shell, enter: php -i
- 通过在php页面中添加phpinfo()并显示页面(如下图)
- 在 shell 中输入:php -i
Next, you can find the information in the Loaded Configuration file (so here it's /user/local/etc/php/php.ini)
接下来,您可以在加载的配置文件中找到信息(所以这里是/user/local/etc/php/php.ini)
Sometimes, you have indicated (none), in this case you just have to put your custom php.ini that you can find here: http://git.php.net/?p=php-src.git;a=blob;f=php.ini-production;hb=HEAD
有时,您已指出(无),在这种情况下,您只需将您可以在此处找到的自定义 php.ini 放入:http: //git.php.net/?p=php-src.git;a= blob ;f=php.ini-production;hb=HEAD
I hope this answer will help.
我希望这个答案会有所帮助。


