How to Increase the WordPress Maximum Upload File Size
Posted by Dexter Nelson: Tuesday, December 13, 2016 (1:42 PM)
How to Increase the WordPress Maximum Upload File Size
So, have you ever tried to increase the upload file size in WordPress and every solution failed?
Yeah, me too.
I started a new WP blog for a project -- and before you ask...
No, I don't always use my CGI Blog. It was design for corporate use so it's like using a jackhammer to drive a nail.
Anyway, I create this new blog and it's going great. Then one day I found myself having to edit like every feature image because of a stupid 2M limit.
I spent about an hour trying to find a way to increase the maximum upload file size limit and nothing worked.
The code in the WP-config file? Nope.
The .htaccess file thingy? That didn't work either.
Others say edit the php.ini file, but I have a VPS (Apache) with multiple websites and to be honest?
... I REALLY don't want to change the maximum upload file size for EVERY site on my server. I just needed this one site.
Here's the thing that everyone danced around, but didn't quite say.
WordPress doesn't set your maximum upload file size - your server does.
All WordPress does is read the size from your server's php.ini file.
I found this out going through my WP files.
Don't believe me?
Check out the /wp-includes/media-template.php and the /wp-admin/includes/media.php files in your installation.
There are a few lines of code that looks like this:
$max_upload_size = wp_max_upload_size();
if ( ! \$max_upload_size ) {
$max_upload_size = 0;
}
The if statement basically translates to - if there is no max_upload_size, then the default should be 0.
In other words, if your server doesn't define a max_upload_size, then you can't upload anything.
So here's what I did:
From my SSL, logged in as root.
# find / -name "*php.ini*"
This gave me the results of every php.ini file and I noted there was one in the system folder for each website.
For UNIX based systems:
/system//etc/php.ini
NOTE: varies depending on installation:
/var/www/
/var/www/hosts/
... and so on.
An example might be /var/www/hosts/system/yourdomain.com/etc/php.ini
By default PHP has a limit of 2M, but depending on your host there might be a higher limit.
I edited the php.ini file for the site that I wanted and saved it.
The line to look for is this one.
upload_max_filesize = 2M
I changed it to upload_max_filesize = 5M
Then I restarted Apache.
# /etc/init.d/httpd restart
NOTE 2: I really think this should be the go to option. Work arounds are nice, but they have a way of getting undone or become invalid with upgrades, clean ups, resets, etc.