Modify upload_max_filesize for wordpress Docker containers

If you are using wordpress like me, sometimes you may encounter the problem where wordpress complains about the upload_max_filesize limit exceeded. More specifically, it is an error message like this:

Sorry, there has been an error.
The uploaded file exceeds the upload_max_filesize directive in php.ini.

There are a couple ways to fix this problem. In this post we will walk through the quickest way with changes in docker-compose.yml. So this will be helpful if you are using a docker-compose.yml to deploy the wordpress site.

If you are using wordpress docker image, the file upload limits can be changed by modifying contents in /usr/local/etc/php/conf.d/uploads.ini inside the Docker container. Let’s say we want to set the upload size to 64MB for everything. So we create an uploads.ini in the same directory as docker-compose.yml, with the following contents:

file_uploads = On
memory_limit = 64M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 600

Next, if we already have a running wordpress container, our docker-compose.yml probably has a wordpress configuration somehow like the following.

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     restart: always
     ...

We need to add the mapping of the just created uploads.ini to the right place in the container. So we will use volumes. We can add the texts below for wordpress:

volumes:
   - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini

Now the config should look something like this:

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     restart: always
     volumes:
       - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini

Save the file and rebuild the docker containers. We should now see the upload limit becomes 64MB. Of course, we can change the number as necessary.

Leave a ReplyCancel reply