Last Updated on 2021-11-10 by Clay
The most of WordPress website that their server has configured the upload file maximum size limit. Take my website as example, the latest website is 2MB limit.
But the new website is a game information sharing site! The news articles have no any high quality picture is very terrible.
So, I try to change the upload files maximum size on WordPress.
Modification Method
Three methods are circulating on the Internet, and I will record then as follows:
- Edit functions.php (Unsuccessful)
- Edit .htaccess (Unsuccessful)
- Edit php.ini (I have no this file)
- Edit docker-compose.yml (Suitable for users who use
docker-compose
the build WordPress like me)
Method One: Edit functions.php
functions.php file should be located in the theme folder.
Add the following code at the file bottom:
@ini_set( 'upload_max_filesize', '20M' );
@ini_set( 'post_max_size', '20M');
@ini_set( 'memory_limit', '64M' );
@ini_set( 'max_execution_time', '300' );
Method Two: Edit .htaccess
.htaccess file should be located in the root directory of website.
Add the following settings:
@ini_set( 'upload_max_filesize', '20M' ); // 單一檔案大小上限
@ini_set( 'post_max_size', '20M'); // POST 資料大小上限
@ini_set( 'memory_limit', '64M' ); // 記憶體上限
@ini_set( 'max_execution_time', '300' ); // 執行時間上限(s)
Method Three: Edit php.ini
The php.ini file is not simply adding settings, but finding the following settings to change the values.
upload_max_filesize = 20M
post_max_size = 20M
memory_limit = 64M
max_execution_time = 300
Method Four: Add settings in docker-compose.yml
Then I suddenly remembered that when I deployed the website, I used docker-compose
to deploy, and the tool itself does not have the php.ini file.
So I started looking for a way to change the upload size limit for this deployment.
First, you need to create a uploads.ini file at the same directory of docker-compose.yml, and wrote in it:
file_uploads = On
memory_limi = 500M
upload_max_filesize = 500M
post_max_size = 500M
max_execution_time = 600
Then add the following setting into docker-compose.yml file:
volumes:
- ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
The architecture of volumes is:
services:
└ wordpress:
└ volumes:
Then run the following command:
sudo docker-compose up -d --build
Your upload file limit has been successfully increased!
References
- https://www.viralpatel.net/local-wordpress-docker/
- https://kinsta.com/blog/increase-max-upload-size-wordpress/
- https://www.cloudways.com/blog/increase-media-file-maximum-upload-size-in-wordpress/