Unable to increase file upload limit in WordPress Docker container

I’m having trouble raising the file upload limit to 150MB in my WordPress Docker setup. I’ve made an upload.ini file and linked it to the container but the WordPress media uploader still shows the same limit.

My docker-compose.yml file looks like this:

version: '2'
services:
  database:
    image: mariadb:latest
    volumes:
      - database_files:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: secretpass
      MYSQL_DATABASE: wp_site
      MYSQL_USER: wp_user
      MYSQL_PASSWORD: userpass

  wp_site:
    depends_on:
      - database
    build: ./wp_folder
    ports:
      - "8080:80"
    restart: always
    environment:
      WP_DB_HOST: database:3306
      WP_DB_PASSWORD: userpass
    volumes: 
      - ./upload.ini:/usr/local/etc/php/conf.d/upload.ini 
volumes:
    database_files:

And my upload.ini file has these settings:

file_uploads = On
memory_limit = 256M
upload_max_filesize = 150M
post_max_size = 150M
max_execution_time = 300

I’ve checked the container with docker inspect and the volume seems to be mounted correctly. Any ideas why the upload limit isn’t changing?

In my experience with WordPress in Docker, the issue is often due to the custom ini file not being read as expected. It might be that the PHP configuration files are loaded in a specific order and your settings are being overridden. You could try rebuilding the Docker image so that the new ini file is part of the build and verify that no other configuration file is resetting the limits. Also, double-check that there are no caching mechanisms interfering with the new settings.

Rebuilding and testing the container normally resolves this issue.

hey lucask, have u tried adding the upload settings directly to your wp-config.php file? sometimes docker can be finicky with custom ini files. just add these lines:\n\n@ini_set( ‘upload_max_size’ , ‘150M’ );\n@ini_set( ‘post_max_size’, ‘150M’);\n@ini_set( ‘memory_limit’, ‘256M’ );\n\nmight do the trick without messing with docker configs

I’ve dealt with this exact issue before, and it can be frustrating. One thing that worked for me was modifying the Apache configuration instead of relying solely on PHP settings. Try creating a custom .htaccess file in your WordPress root directory with these lines:

php_value upload_max_filesize 150M
php_value post_max_size 150M
php_value memory_limit 256M
php_value max_execution_time 300

Then, make sure to mount this .htaccess file in your docker-compose.yml:

volumes:

  • ./custom.htaccess:/var/www/html/.htaccess

This approach bypasses potential conflicts with PHP’s configuration loading order in Docker environments. Remember to restart your container after making these changes. If it still doesn’t work, you might need to check if mod_php is enabled in your Apache configuration within the container.