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.
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.
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.
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.
The Maximum upload file size is being displayed: 2 MB.
Increasing the maximum WordPress file size in Docker
Find the running container by typing:
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
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:
Display the contents of the .htaccess file by running the following command:
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:
That’s all, you’re good to go. WordPress should display the adjusted values when you Add New item to your media.
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.