简体   繁体   English

php.ini:哪一个?

[英]php.ini: which one?

I moved from my old apache to nginx and php 5.3.10. 我从旧的apache转移到nginx和php 5.3.10。 And when I tried to modify php.ini to suit my needs, I found there are 3 of them: 当我尝试修改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? 我应该编辑哪一个?

Generally speaking, the cli/php.ini file is used when the PHP binary is called from the command-line. 一般来说,从命令行调用PHP二进制文件时使用cli/php.ini文件。
You can check that running php --ini from the command-line. 您可以php --ini检查运行php --ini

fpm/php.ini will be used when PHP is run as FPM -- which is the case with an nginx installation. 当PHP作为FPM运行时,将使用fpm/php.ini - 这是nginx安装的情况。
And you can check that calling phpinfo() from a php page served by your webserver. 您可以检查从您的网络服务器提供的php页面调用phpinfo()

cgi/php.ini , in your situation, will most likely not be used. 在你的情况下, cgi/php.ini很可能不会被使用。


Using two distinct php.ini files (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,另一个用于从Web服务器提供页面)经常完成,并且有一个主要优点:它允许您在每种情况下具有不同的配置值。

Typically, in the php.ini file 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. 通常,在Web服务器使用的php.ini文件中,您将指定相当短的max_execution_time :网页应该快速提供,如果页面需要超过几十秒(默认为30秒) ,这可能是因为一个错误 - 应该停止页面的生成。
On the other hand, you can have pretty long scripts launched from your crontab (or by hand), which means the php.ini file that will be used is the one in cli/ . 另一方面,您可以从crontab(或手动)启动相当长的脚本,这意味着将使用的php.ini文件是cli/ For those scripts, you'll specify a much longer max_execution_time in cli/php.ini than you did in fpm/php.ini . 对于这些脚本,您将在cli/php.ini比在fpm/php.ini更长的max_execution_time

max_execution_time is a common example ; max_execution_time是一个常见的例子; you could do the same with several other configuration directives, of course. 当然,你可以用其他几个配置指令做同样的事情。

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/ 导航到您的Web服务器根文件夹,例如/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.phphttp://www.example.com/info.php

Here you will see the php.ini path under Loaded Configuration File : 在这里,您将看到Loaded Configuration File下的php.ini路径:

的phpinfo

Make sure you delete info.php when you are done. 确保在完成后删除info.php

It really depends on the situation, for me its in fpm as I'm using PHP5-FPM. 这真的取决于具体情况,因为我使用的是PHP5-FPM。 A solution to your problem could be a universal php.ini and then using a symbolic link created like: 您的问题的解决方案可能是一个通用的php.ini,然后使用创建的符号链接,如:

ln -s /etc/php5/php.ini php.ini

Then any modifications you make will be in one general .ini file. 然后,您所做的任何修改都将在一个通用.ini文件中。 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. 没有多个位置被攻击在一起。

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) 通过在php页面中添加phpinfo()并显示页面(如下图所示)
  • From the shell, enter: php -i 从shell中输入:php -i

Next, you can find the information in the Loaded Configuration file (so here it's /user/local/etc/php/php.ini) 接下来,您可以在Loaded Configuration文件中找到相关信息(所以这里是/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中生产; HB = HEAD

I hope this answer will help. 我希望这个答案会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM