Increase Maximum Upload Limit In WordPress (LAMP/LEMP)

Hi :slightly_smiling_face:

By default, maximum upload limit in PHP is very small (2MB only). It may cause trouble while uploading large size themes and plugins.

Maximum upload limit is controlled by php.ini file, so it can be increased by editing php.ini file.

This is quick tutorial on how to increase maximum upload limit in WordPress by editing php.ini file.

Please adjust commands according to PHP version.

#1 For LAMP Stack

  • Use command below to update php.ini
nano /etc/php/7.2/cgi/php.ini
  • Under File uploads section, increase upload_max_filesize from 2M to 64M or higher.

Alternatively, you can directly edit upload_max_filesize using command below.


sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 64M/g' /etc/php/7.2/cli/php.ini

Similarly, you can also increase post_max_size, max_file_uploads and max_execution_time.


sed -i 's/post_max_size = 8M/post_max_size = 64M /g' /etc/php/7.2/cli/php.ini
sed -i 's/max_file_uploads = 20 /max_file_uploads = 30  /g' /etc/php/7.2/cli/php.ini
sed -i 's/max_execution_time = 30 /max_execution_time = 300  /g' /etc/php/7.2/cli/php.ini

#2 For LEMP Stack

  • Edit and update upload_max_filesize using the below command.
nano /etc/php/7.2/fpm/php.ini
  • Alternatively, use below command for automatic search and replace.
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 64M/g' /etc/php/7.2/fpm/php.ini
systemctl restart php7.2-fpm.service
  • Similarly, you can also increase post_max_size, max_file_uploads and max_execution_time in LEMP stack.
sed -i 's/post_max_size = 8M/post_max_size = 64M /g' /etc/php/7.2/fpm/php.ini
sed -i 's/max_file_uploads = 20 /max_file_uploads = 30  /g' /etc/php/7.2/fpm/php.ini
sed -i 's/max_execution_time = 30 /max_execution_time = 300  /g' /etc/php/7.2/fpm/php.ini
systemctl restart php7.2-fpm.service

Have any doubt or query? Please ask related questions below.

#dailydose

Regards

Rishi

6 Likes