Home » Php » nginx – Cannot change upload_max_filesize or post_max_size in php.ini

nginx – Cannot change upload_max_filesize or post_max_size in php.ini

Posted by: admin July 12, 2020 Leave a comment

Questions:

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 am currently running an Amazon EC2 instance running.

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

upload_max_filesize=10M
post_max_filesize=20M

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

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

phpinfo() indicates that the file I am editing is the one loaded (/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.

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

ini_set() does not work either.

I’m at a bit of a loss.

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

How to&Answers:

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

Answer:

Try to do a command like this:

php --ini

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

Example output:

[[email protected] ~]$ 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

Answer:

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

There are 2 files which hold settings

/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.

Answer:

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.

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.

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

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

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).

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

Answer:

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

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.

Answer:

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

Answer:

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_filesize and post_max_size but these were being ignored and phpinfo() was returning the default values. I had restarted Apache, and also checked the additional .ini files being loaded with no joy.

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-F to find the original instance of the declaration, and then edit that rather than adding your own 😉