Sometimes, we need to upload large attachments to our WordPress site, but we are met with an error stating “Maximum upload file size: 2 MB.” This can be frustrating when we know we have plenty of server space. Why is there a limit even for slightly larger images?
In reality, this limit is often not set by WordPress itself but by the server environment. For security and performance reasons, server software has default limits on request sizes. For WordPress, the maximum upload size is primarily influenced by PHP and Nginx settings.
Increasing the Maximum Upload Size in PHP
Most PHP server settings are found in the php.ini file. To increase the allowed upload size, we first need to locate this file and then modify the relevant settings.
Finding the php.ini File
On your server, you can easily find the location of your PHP configuration file by running:
php -i | grep 'php.ini'This will typically return the path to your loaded configuration file, such as /usr/local/etc/php/7.3/php.ini. Use your preferred editor to open the file and add or modify the following settings:
upload_max_filesize = 128M
post_max_size = 128M
memory_limit = 256M
max_execution_time = 300
max_input_time = 300Here’s what these settings do:
- upload_max_filesize: The maximum size of an individual uploaded file.
- post_max_size: The maximum size of an entire POST request.
- memory_limit: The maximum amount of memory a PHP process can use.
- max_execution_time: The maximum time a PHP script is allowed to run.
- max_input_time: The maximum time allowed for script input parsing.
The primary settings affecting upload size are upload_max_filesize and post_max_size. The others help prevent large uploads from timing out or consuming too much memory, which could otherwise slow down your site.
If your server supports per-user configuration via .user.ini, you can also place these settings there. After saving, remember to restart or reload the PHP-FPM process for changes to take effect.
Increasing the Limit via .htaccess (Apache)
If you are using an Apache server and it supports .htaccess files, you can add these lines to your site’s .htaccess file to achieve the same result:
php_value upload_max_filesize 128M
php_value post_max_size 128M
php_value memory_limit 256M
php_value max_execution_time 300
php_value max_input_time 300Increasing the Limit in Nginx
Even if you increase the limit in PHP, you might still see an upload error if Nginx has its own request body limit. You can increase this by adding a line to your Nginx http or server configuration block:
http {
client_max_body_size 128m;
}After updating the config, reload Nginx (service nginx reload) and restart PHP-FPM. Your new upload limit should now be active. Remember not to set these limits excessively high to avoid potential performance impacts. For very large files, consider using FTP instead.
