44

I'm running php5-fpm under Nginx on Ubuntu 14.04. I want to increase the max upload size.

I have edited my /etc/php5/fpm/php.ini to have the following lines defined as below:

upload_max_filesize = 20M post_max_size = 25M

and I restarted php5-fpm and nginx but phpinfo() is still showing the limits to be 8M and 2M for post and upload respectively.

Is there anything I have missed here?

1
  • check if the php.ini path in phpinfo() is same as you mentioned the question Jul 10, 2014 at 5:55

6 Answers 6

65

Nginx

  • client_max_body_size

PHP

  • post_max_size
  • upload_max_filesize

And restart or reload php fpm.

Source: http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size

2
  • Which file to put this in for PHP? conf.d/mysite.ini or pool.d/mysite.ini?
    – Jonathan
    Sep 7, 2020 at 7:29
  • @Jonathan in my case, on Ubuntu 20.04, I put the PHP settings in /etc/php/7.4/fpm/php.ini and the Nginx setting in /etc/nginx/sites-available/example.com to only affect that single site
    – chrki
    Mar 29, 2021 at 21:31
28

Instead of changing php.ini file, I add all information in the nginx sites-available files. I see you got your answer long time ago, but this is the way I do it:

In my virtualhost under server {} block, I added:

client_max_body_size 128m;

Then in the location ~ .php$ {} block I added:

fastcgi_param PHP_VALUE "upload_max_filesize=128M \n post_max_size=128M";

Then restart nginx.

13

I had a problem with restarting so I just killed the process and started it manually.

sudo pkill php5-fpm
sudo service php5-fpm start
1
  • 2
    This seems a comment on the answer accepted in 2014
    – Dave M
    Jul 26, 2015 at 12:45
6

The issue was with the restarting of php5-fpm. It seems there is a bug where sometimes some child processes are not terminated upon restart. I had to manually kill the processes with kill <process id> having identified them with ps -ef.

I was then able to fully restart php5-fpm which enacted my config changes.

3

I know this is an old question that's already been answered. But I wanted to comment here for @harryg and others that come after me.

Your issue was with restarting php5-fpm being buggy. As of this writing, the issue seems to have been fixed, and restarting php5-fpm on ubuntu is as simple as running the following command:

service php5-fpm restart

NOTE: I'm currently running this version of php5-fpm: PHP 5.5.9-1ubuntu4.9 (fpm-fcgi) (built: Apr 17 2015 11:44:58)

Hope someone finds this helpful.

1

It sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field. Here’s an example of increasing the limit to 50MB in /etc/nginx/nginx.conf file.

Set in http block which affects all server blocks (virtual hosts).

http {
    ...
    client_max_body_size 50M;
}

Set in server block, which affects a particular site/app

server {
    ...
    client_max_body_size 50M;
}

Set in location block, which affects a particular directory (uploads) under a site/app.

location /uploads {
    ...
    client_max_body_size 50M;
} 

Save the file and restart Nginx web server to apply the recent changes using following command.

# systemctl restart nginx
3
  • this configures apache, not php
    – asdmin
    Aug 3, 2019 at 10:55
  • 1
    No, this for php5-fpm under Nginx configuration. Aug 3, 2019 at 11:01
  • these are options for nginx's ngx_http_core_module. Definitely do not configure any php settings.
    – asdmin
    Aug 5, 2019 at 19:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .