Managing WordPress Upload Sizes For Different Sites On One Server with .INI Files

By May 9, 2018March 5th, 2021Blog, Web Development

I manage a few VPS servers that have multiple websites on them, one of these servers having close to 40 WordPress websites on it. One question I get asked about is how to give every site a different upload value and override the default PHP directive of 4MB or 8MB or the default 2MB that WordPress demands in a vanilla installation.

Before we get started, think about your client first. There is a reason WordPress and PHP limit the upload size of files. You don’t want a client with a photography site to be able to upload 24MB 4k images in a photo gallery because they don’t know any different. Their site would never load and you’d have a whole world of troubleshooting to do. That limit is pretty awesome when it comes to saving bandwidth and server resources.

But what about the client who is doing podcasts or large audio or video files. They can have files upwards of 50MB – 150MB that need to get upload. Obviously you don’t want to change the PHP APACHE directive and give ALL your clients the ability to upload huge files right? Well thats where php.ini and .user.ini files come in.

The php.ini file has a blanket effect for all directories on the server. The php.ini file can be used in many ways, some of which include:

  • upload_max_filesize: Limiting the maximum file size that can be uploaded
  • max_file_uploads: Limiting the maximum number of files that can be uploaded at the same time
  • max_execution_time: Limiting the maximum time a script can run before it’s terminated

php.ini uses commands called “directives” to communicate with the server. You can find a list of php.ini directives on the PHP documentation site. Make sure you check the “modes” of the directives so you know they are compatible with the php.ini file. Here is a sample directive that dictates all uploads will be 2MB, just add this code to a php.ini file and drop it in the root directory. (You may have to restart the PHP service or stop then start all php processes to get it to work.)

; MB user can upload via php
upload_max_filesize = 2M
post_max_size = 2M
max_execution_time = 300

How the php.ini file is configured will dictate how all your server directories are configured. However, if you want to make an exception for a directory, you would use a .user.ini file.

A .user.ini file controls the PHP settings of a single directory. It will only affect the directory it is in. However, each directory may have a user.ini file.

In this example, and both have an overriding .user.ini file giving those sites access to a larger upload size (10MB & 100MB). The other two sites are still dictated by the php.ini file and are only given access to uploading 2MB max.


So this little trick works with other things too, like setting different versions of PHP, using different timezones, and restricting access to PHP functions on a site by site basis (like CURL or ZEND for example). Have Fun with that!

Leave a Reply