To follow this guide, your WordPress is required to be installed on a VPS or a cloud server or a dedicated server with root privileges on SSH. This guide does not apply to WordPress sites that are using shared hosting (such users can use WordPress plugins which increases the limit).
LAMP server customization is complicated since not everything is documented clearly. It is common to try changing the value of the upload_max_filesize
directive in some php.ini
without any effective result. This article will address the two errors while trying to change the value.
Changing Value of Which php.ini File Will Work?
In the whole system, there are 3-4 php.ini
files. Normally, we do not use PHP’s built-in server. Depending on the module in use, the settings of a specific php.ini
file get honoured because the way of utilizing PHP becomes different. SSH to your server, and change the directory to /etc
:
---
1 | cd /etc |
Run this command to view the path of the php.ini
files which have the phrase “post_max_size”:
1 | grep -rl "post_max_size" | xargs ls -lrth |
You’ll get an output like this:
1 2 3 4 5 | -rw-r--r-- 1 root root 71K Feb 14 13:27 php/7.2/fpm/php.ini -rw-r--r-- 1 root root 71K Feb 14 13:27 php/7.2/embed/php.ini -rw-r--r-- 1 root root 71K Feb 14 13:27 php/7.2/cgi/php.ini -rw-r--r-- 1 root root 71K Apr 17 10:37 php/7.2/apache2/php.ini -rw-r--r-- 1 root root 70K May 2 15:18 php/7.2/cli/php.ini |
When you are using mod_php and mpm prefork, then editing the /etc/php/7.2/apache2/php.ini
should work.
When you are using php-fpm and MPM Event, then editing the /etc/php/7.2/fpm/php.ini
should work.
For wider compatibility, you have to edit all the php.ini
files.
What to Change?
You have to change the values of at least these three directives:
1 2 3 | memory_limit post_max_size upload_max_filesize |
Where the value of memory_limit > max_post_size >= upload_max_filesize. For example, you can set the values 10MB, 8MB, 6MB or 8MB. For example:
1 2 3 | memory_limit = 512M upload_max_filesize = 256M post_max_size = 256M |
Depending on your setup, run the appropriate commands to test and gracefully restart Apache:
1 2 3 | apachectl configtest service php7.2-fpm restart sudo /etc/init.d/apache2 reload |
Check WordPress for upload size. It should be fixed now.