无法在 php.ini 中更改 upload_max_filesize 或 post_max_size

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13272964/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 05:05:03  来源:igfitidea点击:

Cannot change upload_max_filesize or post_max_size in php.ini

nginxamazon-ec2phpec2-ami

提问by Matt Edmonston

Bear in mind, I am no sysadmin, I am just a developer. I cannot find anyone with the exactproblem as me, just similar, and none of their "fixes" seem to work.

请记住,我不是系统管理员,我只是一名开发人员。我找不到和我一样有确切问题的人,只是相似,而且他们的“修复”似乎都不起作用。

I am currently running an Amazon EC2 instance running.

我目前正在运行一个 Amazon EC2 实例。

CentOS 6.2
Nginx 1.2.2
PHP 5.3.16 with APC
Percona 5.5.24 // not currently using this as I am using an RDS

I have set my php.ini (/etc/php.ini) settings to the following

我已将我的 php.ini (/etc/php.ini) 设置设置为以下内容

upload_max_filesize=10M
post_max_filesize=20M

After reloading the config, using php -ivia ssh, these settings seemed to be loaded. Showing upload_max_filesize=10M, etc.

重新加载配置后,php -i通过 ssh使用,这些设置似乎已加载。显示upload_max_filesize=10M

When using phpinfo()or ini_get, both options are returned as 4M

使用phpinfo()or 时ini_get,两个选项都返回为4M

phpinfo()indicates that the file I am editing is the one loaded (/etc/php.ini).

phpinfo()表示我正在编辑的文件是加载的文件 ( /etc/php.ini)。

I have also run php -i | grep "\.ini"to check which files are loaded, and there are no unnecessary loaded configs. I even went through each loaded file individually to check they didn't have the settings inside.

我还运行php -i | grep "\.ini"检查加载了哪些文件,并且没有不必要的加载配置。我什至单独检查了每个加载的文件,以检查它们里面没有设置。

Additionally, I have been suggested to try using a .user.iniconfig file. This did not change the values either.

此外,有人建议我尝试使用.user.ini配置文件。这也没有改变值。

ini_set()does not work either.

ini_set()也不起作用。

I'm at a bit of a loss.

我有点不知所措。

EDIT: not sure this will help, but I am using this AMI http://megumi-cloud.com/

编辑:不确定这会有所帮助,但我正在使用这个 AMI http://megumi-cloud.com/

采纳答案by Matt Edmonston

I got in contact with the guys who made the AMI and found out there are additional configuration files that override the php.ini

我联系了制作 AMI 的人,发现还有其他配置文件覆盖了 php.ini

There are 2 files which hold settings

有 2 个文件保存设置

/etc/php-fpm.d/www.conf // This is the file which holds upload_max_filesize and post_max_size, among others
/etc/php-fpm.conf

Obviously the locations may differ on different configurations, but hopefully this will help give someone an idea of what else to look for.

显然,不同配置的位置可能会有所不同,但希望这将有助于让人们了解还需要寻找什么。

回答by Rupesh Kumar

Filename:

文档名称:

nginx/sites-available/default

Add:

添加:

location ~ \.php$ {
      fastcgi_param PHP_VALUE "upload_max_filesize = 50M \n post_max_size=51M";
}

Run: From command line: sudo service nginx restart

运行: 从命令行: sudo service nginx restart

回答by user1351312

Try to do a command like this:

尝试执行这样的命令:

php --ini

It will show you which ini files are loaded by php.

它会告诉你 php 加载了哪些 ini 文件。

Example output:

示例输出:

[admin@staging ~]$ php --ini
Configuration File (php.ini) Path: /usr/local/etc
Loaded Configuration File:         /usr/local/etc/php.ini
Scan for additional .ini files in: /usr/local/etc/php
Additional .ini files parsed:      /usr/local/etc/php/extensions.ini

回答by Jesse Bunch

If you explicitly set those values in your php.ini file and they are not the same when you run your PHP script, then something has overridden them. You know your php.ini settings are correct because the CLI version of PHP info shows the new settings.

如果您在 php.ini 文件中明确设置了这些值,并且在您运行 PHP 脚本时它们不相同,那么某些东西已经覆盖了它们。您知道 php.ini 设置是正确的,因为 PHP 信息的 CLI 版本显示了新设置。

I have also run php -i | grep ".ini" to check which files are loaded, and there are no unnecessary loaded configs. I even went through each loaded file individually to check they didn't have the settings inside.

我也运行了 php -i | grep ".ini" 来检查加载了哪些文件,并且没有不必要的加载配置。我什至单独检查了每个加载的文件,以检查它们里面没有设置。

This is great, but it's telling you what .ini files have been loaded from the PHP CLI---not your application.

这很棒,但它告诉您从 PHP CLI 加载了哪些 .ini 文件——而不是您的应用程序。

You need to check the Additional .ini files parsedsection of your phpinfo()output to see exactly what files are being loaded from your web server. One of those files is overriding your settings.

您需要检查输出的附加 .ini 文件解析部分,phpinfo()以准确查看正在从您的 Web 服务器加载的文件。其中一个文件覆盖了您的设置。

Finally, if none of those files turn out to be the culprit, you should do a global find on ini_set()in your project to make sure some rogue script isn't setting those values for you (trying to be helpful).

最后,如果这些文件都不是罪魁祸首,您应该ini_set()在您的项目中进行全局查找,以确保某些流氓脚本没有为您设置这些值(试图提供帮助)。

Keep digging, you'll find the culprit in one of those two places.

继续挖掘,你会在这两个地方之一找到罪魁祸首。

回答by Andri Lareida

I had the same problem of the PHP application complaining about the upload file size. Using the command lilne version of php (php --ini)I determined the php.ini file to be: /etc/php5/cli/php.ini

我遇到了 PHP 应用程序抱怨上传文件大小的相同问题。使用命令 lilne version of php (php --ini) 我确定 php.ini 文件为:/etc/php5/cli/php.ini

with php -info I verified the settings. but still the application gave me the same error. The I discovered that PHP has different ini files for CLI and Apache. Check your /etc/php5 folder it has apache2 and cli folders with seperate ini files inside. Just edit /etc/php5/cli/php.ini to change the apache settings.

使用 php -info 我验证了设置。但应用程序仍然给了我同样的错误。我发现 PHP 对 CLI 和 Apache 有不同的 ini 文件。检查您的 /etc/php5 文件夹,它有 apache2 和 cli 文件夹,里面有单独的 ini 文件。只需编辑 /etc/php5/cli/php.ini 即可更改 apache 设置。

回答by Sam Campsall

Bear in mind, I am no sysadmin, I am just a developer. I cannot find anyone with the exact problem as me, just similar, and none of their "fixes" seem to work.

请记住,我不是系统管理员,我只是一名开发人员。我找不到和我一样有确切问题的人,只是相似,而且他们的“修复”似乎都不起作用。

I was in the same boat, with the same problem and turns out they were related!

我在同一条船上,遇到同样的问题,结果它们是相关的!

I had included lines to increase upload_max_filesizeand post_max_sizebut these were being ignored and phpinfo()was returning the default values. I had restarted Apache, and also checked the additional .inifiles being loaded with no joy.

我已经包含要增加的行upload_max_filesizepost_max_size但这些行被忽略并phpinfo()返回默认值。我重新启动了 Apache,并检查了.ini正在加载的其他文件,但并不高兴。

The solution was that I had added my lines to increase these parameters near the beginning of the file, and they were being overwritten later on in the same file!

解决方案是我在文件开头附近添加了我的行来增加这些参数,并且它们稍后在同一个文件中被覆盖!

So, if you're having this problem, make sure you're not making the same stupid mistake I was, and Ctrl-Fto find the original instance of the declaration, and then edit that rather than adding your own ;)

因此,如果您遇到此问题,请确保您没有犯与我相同的愚蠢错误,并Ctrl-F找到声明的原始实例,然后对其进行编辑,而不是添加您自己的 ;)

回答by hexicle

Restart your web server. That's all you need to do.

重新启动您的网络服务器。这就是你需要做的。