Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save savepong/3e8b5b88078df524c1172124bc7a71fd to your computer and use it in GitHub Desktop.
Save savepong/3e8b5b88078df524c1172124bc7a71fd to your computer and use it in GitHub Desktop.

Increasing PHP Upload Limits in Docker WordPress

When working with WordPress in Docker, you may need to increase the default file upload size limits. Here are multiple methods to accomplish this:

Method 1: Using Custom php.ini File (Recommended)

This is the cleanest approach that persists through container restarts.

  1. Create a custom PHP configuration file:

    mkdir -p ~/websites/custom-php
    nano ~/websites/custom-php/custom.ini
  2. Add these configurations to the file:

    upload_max_filesize = 64M
    post_max_size = 64M
    memory_limit = 128M
    max_execution_time = 300
  3. Update your docker-compose.yml to mount this file:

    website_wordpress:
      image: wordpress:latest
      platform: linux/arm64
      container_name: website_wordpress
      # ... other settings ...
      volumes:
        - ./sites/website/wordpress:/var/www/html
        - ./custom-php/custom.ini:/usr/local/etc/php/conf.d/custom.ini
      # ... rest of configuration ...
  4. Restart your containers:

    docker-compose down
    docker-compose up -d

Method 2: Using .htaccess File

If you prefer not to modify docker-compose.yml:

  1. Connect to your WordPress container:

    docker exec -it website_wordpress bash
  2. Edit or create the .htaccess file:

    nano /var/www/html/.htaccess
  3. Add these lines:

    php_value upload_max_filesize 64M
    php_value post_max_size 64M
    php_value memory_limit 128M
    php_value max_execution_time 300
    
  4. Exit the container:

    exit

Method 3: Using wp-config.php

Another approach is to add these settings to wp-config.php:

  1. Connect to your WordPress container:

    docker exec -it website_wordpress bash
  2. Edit wp-config.php:

    nano /var/www/html/wp-config.php
  3. Add these lines before "That's all, stop editing!":

    /* Increase upload limits */
    @ini_set('upload_max_filesize', '64M');
    @ini_set('post_max_size', '64M');
    @ini_set('memory_limit', '128M');
    @ini_set('max_execution_time', '300');
  4. Exit the container:

    exit

Verify Your Changes

To confirm the new settings are applied:

  1. Create a temporary PHP info file:

    docker exec -it website_wordpress bash -c "echo '<?php phpinfo(); ?>' > /var/www/html/info.php"
  2. Visit https://yourdomain.com/info.php in your browser

  3. Search for "upload_max_filesize" and "post_max_size" to check the current values

  4. For security, delete the info file after verification:

    docker exec -it website_wordpress bash -c "rm /var/www/html/info.php"

Important Notes

  • If using the .htaccess method, ensure that your Apache configuration allows overriding PHP settings
  • The values (64M, 128M, etc.) can be adjusted based on your specific requirements
  • Always consider server resource limitations when increasing these values
  • Some hosting environments may have additional restrictions that override these settings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment