9

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/

Matt Edmonston
  • 151
  • 1
  • 2
  • 8
  • what is your real problem?are you trying to upload the files through any interface form or what? – Vikas Umrao Nov 07 '12 at 15:42
  • Tell more about your PHP SAPI. `.user.ini` is for CGI/FCGI instances. In Apache you were to use `.htaccess` alternatively. PHP5.3.3+ seemingly provides a environment variable workaround for nginx: http://forum.nginx.org/read.php?2,22556,99839#msg-99839 – mario Nov 07 '12 at 15:43
  • It's just a basic image upload script, for avatars, but the default upload amount it too low. The server is running fpm-fcgi. I did try `.htaccess` file, but for obvious reasons, it did nothing. – Matt Edmonston Nov 07 '12 at 15:58
  • @sivann I am not sure, as it was using a preconfigured AMI from the amazon community section when creating a new instance. Checking its version just returns the php version, `5.3.16`. Is there a way to check? – Matt Edmonston Nov 07 '12 at 16:14
  • @sivann Oh, I misunderstood. `CentOS release 6.2` – Matt Edmonston Nov 07 '12 at 16:30

8 Answers8

16

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

Rupesh Kumar
  • 161
  • 1
  • 3
7

Try to do a command like this:

php --ini

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

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
user1351312
  • 133
  • 1
  • 5
3

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.

Matt Edmonston
  • 151
  • 1
  • 2
  • 8
  • 7
    I encountered the same problem and edited the `/etc/php5/fpm/php.ini` file by increasing `upload_max_filesize = 10M`. I then had to `sudo service php5-fpm restart` & `sudo service nginx restart` for it to finally work (this was on Ubuntu 12.04 though). – rs77 Jun 16 '13 at 05:53
  • 2
    Doing `sudo service php5-fpm restart` and `sudo service nginx restart` worked for me where `sudo /etc/init.d/php5-fpm restart` and `sudo /etc/init.d/nginx restart` didn't! – Anson Kao Nov 03 '14 at 18:17
  • This! `sudo service php-fpm restart` and `sudo service nginx restart` in my case – orszaczky Jun 05 '15 at 12:58
2

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.

Jesse Bunch
  • 6,651
  • 4
  • 36
  • 59
  • Thanks, Jesse. I'll run through those and let you know on the outcome. – Matt Edmonston Nov 07 '12 at 17:02
  • I've just been through all the .ini files that are loaded in the additional section of `phpinfo()`, and have also run a search through all the files for `ini_set()`. Unfortunately neither of these were the problem. – Matt Edmonston Nov 07 '12 at 17:25
  • That's all I've got then. For me, it has always been one of those two places. – Jesse Bunch Nov 07 '12 at 17:29
1

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.

0

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

hexicle
  • 2,121
  • 2
  • 24
  • 31
  • 1
    As stated in my answer: there were additional config files, which I was unaware of, which were overriding the main config file. – Matt Edmonston Feb 19 '14 at 11:20
0

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

Sam Campsall
  • 128
  • 3
  • 14
0

Similar to what has been noted here already: On Ubuntu 16.04 I did systemctl reload php7.0-fpm for my change to upload_max_filesize to come into effect. I did not have to reload/restart nginx.

(php7.0 was the current version of PHP installed on my machine.)

Bjorn
  • 1,090
  • 8
  • 12