Increase Upload File Size Limit with Ubuntu/PHP

To increase the upload size limit, edit the PHP configuration file.

If you using php7.4 then replace 8.1 to 7.4 in the below commands

sudo nano /etc/php/8.1/fpm/php.ini

Find the following line.

upload_max_filesize = 2M

Change the value like below. Note that this value should not be larger than the attachment size limit set by Postfix SMTP server.

upload_max_filesize = 50M

Then find the following line.

post_max_size = 8M

Change the maximum size of POST data that PHP will accept.

post_max_size = 50M

Save and close the file. Alternatively, you can run the following two commands to change the value without manually opening the file.

sudo sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /etc/php/8.1/fpm/php.ini

sudo sed -i 's/post_max_size = 8M/post_max_size = 50M/g' /etc/php/8.1/fpm/php.ini

Then restart PHP-FPM.

sudo systemctl restart php8.1-fpm

Nginx also sets a limit of upload file size. The default maximum upload file size limit set by Nginx is 1MB. If you use Nginx, edit the Nginx configuration file.

sudo nano /etc/nginx/conf.d/mail.example.com.conf

Add the following line in the SSL virtual host.

client_max_body_size 50M;

Save and close the file. Then reload Nginx for the changes to take effect.

sudo systemctl reload nginx

One Response

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Liked this post? Share with others!

Do you want to boost your business today?

This is your chance to invite visitors to contact you. Tell them you’ll be happy to answer all their questions as soon as possible.