DockerLinuxWordpressdocker compose container wordpress

Increase maximum WordPress upload file size in Docker

Need to increase the maximum upload file size in WordPress running inside your Docker container? In this guide, we are going to show you step for step on how to do this.

Note: If you want to apply this to your WordPress on regular or local hosting, you can do this by skipping the Docker related steps, and start from editing the .htaccess file.


Possible errors

Let’s say you want to update your WordPress but when you run the installer you get the following error:

Download failed.: cURL error 18: transfer closed with x bytes remaining to read.

Installation Failed.

wordpress update failed docker

Or when you try to upload a plugin or a theme you get the following error:

The link you followed has expired.

Please try again.

Wordpress The link you followed has expired


Finding your maximum WordPress upload file size

The easiest way to find your maximum upload file size is by adding a new item to your media library. Go to Media then click on Add New.

wordpress media add new

The Maximum upload file size is being displayed: 2 MB.

wordpress upload size docker maximum upload file size


Increasing the maximum WordPress file size in Docker

Find the running container by typing:

docker ps

wordpress upload size docker list proces status

Get bash access to the container by typing

docker exec -t container_name bash

Replace container_name with the name of your container like in the example below

wordpress upload size docker container execute bash

Move inside your /var/www/html directory (already there if you’re using the standard Docker Compose image).

We want a list of all of the files and sort them to be easily readable by running the following command:

ls -alh

wordpress upload size docker container list hidden files

Display the contents of the .htaccess file by running the following command:

cat .htaccess

wordpress upload size docker display .htaccess file content

Values needed to increase the upload size need to be added between </IfModule> and # END WordPress like in the example above. If you have a standard .htaccess file this should be on lines 11 and 12, if not adjust accordingly to your needs.

Insert values with sed:

sed -i "11i php_value upload_max_filesize 256M" .htaccess && sed -i "12i php_value post_max_size 256M" .htaccess

Now the file should look like this:

wordpress upload size docker htaccess file with php values added

That’s all, you’re good to go. WordPress should display the adjusted values when you Add New item to your media.

wordpress upload size docker upload max size 256MB


Restoring the values

If you want to restore the values or just remove them after completing updates or uploads, you can do this by running the following command:

sed -i "11,12d" .htaccess


Thank you for your time reading our guide on how to increase the maximum WordPress upload file size in Docker. Please leave us a comment if you found it useful.

Would you like to know how to learn Linux the fun way through hacking instead? You can read it over here.

Until the next time – TechGuideReview.

Leave a Reply

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

Post comment