When working with WordPress in Docker, you may need to increase the default file upload size limits. Here are multiple methods to accomplish this:
This is the cleanest approach that persists through container restarts.
-
Create a custom PHP configuration file:
mkdir -p ~/websites/custom-php nano ~/websites/custom-php/custom.ini
-
Add these configurations to the file:
upload_max_filesize = 64M post_max_size = 64M memory_limit = 128M max_execution_time = 300
-
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 ...
-
Restart your containers:
docker-compose down docker-compose up -d
If you prefer not to modify docker-compose.yml:
-
Connect to your WordPress container:
docker exec -it website_wordpress bash
-
Edit or create the .htaccess file:
nano /var/www/html/.htaccess
-
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
-
Exit the container:
exit
Another approach is to add these settings to wp-config.php:
-
Connect to your WordPress container:
docker exec -it website_wordpress bash
-
Edit wp-config.php:
nano /var/www/html/wp-config.php
-
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');
-
Exit the container:
exit
To confirm the new settings are applied:
-
Create a temporary PHP info file:
docker exec -it website_wordpress bash -c "echo '<?php phpinfo(); ?>' > /var/www/html/info.php"
-
Visit
https://yourdomain.com/info.php
in your browser -
Search for "upload_max_filesize" and "post_max_size" to check the current values
-
For security, delete the info file after verification:
docker exec -it website_wordpress bash -c "rm /var/www/html/info.php"
- 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