While working with WordPress or any other PHP-application, you might be faced with the following messages:
- Warning post content-length of bytes exceeds the limit
- The uploaded file exceeds the upload_max_filesize directive in php.ini
- exceeds the maximum upload size for this site
- Fatal error: Allowed memory size of 12345678 bytes exhausted (tried to allocate 2345678 bytes) in /home/username/domain/public_html/wp-includes/plugin.php on line 123
- 413 Error: Request Entity Too Large
These warning or error messages are related to the server settings for maximum upload size or memory limit.
Check your current system settings
File exceeds the upload_max_filesize
You may have encountered the following error message when you are installing Wordpress
The uploaded file exceeds the upload_max_filesize directive in php.ini
Or ...
exceeds the maximum upload size for this site
This occurs when your server has well-defined settings to limit exposure / threat attack vector. In this case for the PHP-setting: Upload Max Filesize (upload_max_filesize) usually inside the php.ini
Usually Wordpress and other programs come with a recommended limit. You should check in your admin-panel or phpinfo() block to find the current value for PHP Upload Max Filesize
and potentially change or influence it to be a higher but minimum setting!
Solutions
The goal is to change to following settings:
memory_limit
upload_max_size
post_max_size
upload_max_filesize
max_execution_time
max_input_time
Example of higher yet "reasonable" settings for shared-webhosting and Wordpress:
memory_limit = 256M upload_max_size = 64M post_max_size = 64M upload_max_filesize = 64M max_execution_time = 180 max_input_time = 1000
Will attach screenshot
Per Site / Virtual Directory Using .htaccess file
Apache allows for .htaccess files to control options for the webserver. This file allows you to manipulate how Apache serves files. (read more here)
This is the way to go forward for most CPanel/Directadmin/Plesk hosting solutions. It is by far the easiest solution out there. It is however not the most secure, but easily the most recommended for shared hosting solutions, giving you, the client, if it works, the most freedom and configurability
php_value memory_limit 256M
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 180
php_value max_input_time 1000
If you know which version of php you are running including the fact if you are running mod_php, you could encapsulate these by adding a IfModule
-block.
In .htaccess you can add:
<IfModule mod_php5.c>
php_value memory_limit 256M
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 180
php_value max_input_time 1000
</IfModule>
<IfModule mod_php7.c>
php_value memory_limit 256M
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 180
php_value max_input_time 1000
</IfModule>
You might also need to add a line with AllowOverride Options
on top to allow for such changes.
Console Access: Changing php.ini
The php.ini file is the default PHP configuration file. If you have access to it and you want settings to change globally, you could do the following:
- Locate the current loaded file (or locate all php.ini)
- Change the values listed above
- Restart the webserver and or php-runtime service (php-fpm)
Contact the Webhoster
If you have no clue what you have to do: Contact your webhoster and ask them to address these issues. Add a link to this post and/or a screenshot of the error, or email them the error message.
Ask them to increase the following values. They might have restrictions on these values. This is normal.