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.
- Installation Failed.
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
Update 5th of June 2020
The composition of .htaccess file has changed so I’ve decided to adjust some things. The values are being inserted before the last line instead of assigning numbers to them.
To add php values:
root@48ac15e755b5:/var/www/html# sed -i '/^# END WordPress.*/i php_value upload_max_filesize 256M\nphp_value post_max_size 256M' .htaccess
Output of modified .htaccess file
root@48ac15e755b5:/var/www/html# cat .htaccess # BEGIN WordPress # The directives (lines) between `BEGIN WordPress` and `END WordPress` are # dynamically generated, and should only be modified via WordPress filters. # Any changes to the directives between these markers will be overwritten. php_value upload_max_filesize 256M php_value post_max_size 256M # END WordPress
To remove php values:
root@48ac15e755b5:/var/www/html# sed -i '/php_value/d' .htaccess
Output of modified .htaccess file:
root@48ac15e755b5:/var/www/html# cat .htaccess # BEGIN WordPress # The directives (lines) between `BEGIN WordPress` and `END WordPress` are # dynamically generated, and should only be modified via WordPress filters. # Any changes to the directives between these markers will be overwritten. # END WordPress
Watch this quick video preview on how it’s done and the final result.
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 install Docker-Compose with WordPress on Fedora 32 as well? You can read it over here.
Until the next time – TechGuideReview.