PHP Developer

My notes and thoughts about Linux, WordPress, PHP and many more.

Override upload_max_filesize and post_max_size on a per site basis in PHP-FPM Apache server

Basic Steps

This quick tutorial shows how you can override upload_max_filesize and post_max_size on a per site basis. This assumes you are using Apache server, PHP-FPM handler and WordPress. This tutorial assumes you have shell access to your server so you can restart Apache or PHP-FPM (this is optional but recommended).

By default, there is only one default php.ini loaded on a server. Sometimes some virtual sites in your server might need specific configuration values that you don’t want to be applied globally.

These are the steps to fix this:

  1. Confirm if you are using PHP-FPM Handler. This is done very easily by using the output of phpinfo.php:

    To determine if you are using PHP-FPM handler is to check the value of Server API. In the above screenshot it’s FPM/FastCGI. So that’s correct.

  2. Confirm if you are using Apache server. Again this is very easy with the output of phpinfo.php. Scroll down and find the field of $_SERVER['SERVER_SOFTWARE']. It should contain Apache. See screenshot:

  3. Now create a file in your WordPress root directory called .user.ini with the following settings to override upload_max_filesize and post_max_size. Example:

  4. The above example shows that you want to override upload_max_filesize with 200 Megabytes and post_max_size with 500 Megabytes
    Make sure its on the root directory of WordPress. Als make sure to put a dot sign before the file name as this is a hidden configuration file like .htaccess. This is how it looks like when this file is created:

    It’s on the same path as the wp-load.php, etc.

  5. Once the .user.ini file is created, restart your Apache server and PHP-FPM:

    It assumes you are using PHP 7.0. If you are using PHP 5.7, simply replace php7.0-fpm with php5.6-fpm.

  6. Re-check again your phpinfo() output and confirm that the Local value is now correct. This value is meant to be active for the specific site with the .user.ini and not applied to all sites in your server.

Important notes

  • There are instances where this fix works without root access (as long as you can create .user.ini in your WordPress root directory ). But it will take some time for the settings to take effect. After you have put the correct value in your .user.ini. You need to refresh your page and wait for like several minutes for the settings to be reflected in your phpinfo. But if you want the fastest results, you will simply need to restart Apache and PHP-FPM.
  • You cannot just set any value to these configuration. These settings are also related with one another and to memory_limit as well. Please read the following guidelines on setting these values correctly:
  • You can also protect your .user.ini from being publicly viewed by adding these lines to your .htaccess:

Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url=""> 

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