WordPress has a default limit of 2MB for any file uploaded to the system.  However, the value is easy to change by adjusting some PHP settings on the server.  Let’s look at two ways to change the configuration values to set the limit to suit our needs.

The 2MB limit is determined by two PHP configuration variables.  These variables are upload_max_filesize and post_max_size.  The values can be set in the php.ini file or a .htaccess file.  Let’s look at each of these options.

Changing the 2MB limit in php.ini

The php.ini file is in the /etc folder by default.  The location also can be confirmed through the “phpinfo” command.  To use this create a file with the .php extension and add the following code:

<?php
phpinfo();
?>

Save the file and place it in the root web folder.  In Linux this is typically found at /var/www/html.  Once the file is in place, browse to it on the web server, and a page full of information will be displayed.  Find the line for the Loaded Configuration File to see the php.ini file the server is using.  Open the file in an editor.
Scroll to find the line where the upload_max_filesize variable is defined.  It will read 2MB by default.  Change it to suits the server needs.  I set my value to 50MB, so the line in my file looks like this.

upload_max_filesize=50MB

Now repeat the process to set the post_max_size variable.

Change the variable then save the file.  Finally, restart the web server to apply the changes.  Then the next time a file is uploaded the new value will be reflected.

 

Changing the 2MB limit in .htaccess

WordPress uses .htaccess for some reasons so you should have one in the root of the application folder.  If the file is not there, then go up a folder level to find it.  Now open the .htaccess file with an editor and verify the variables are not currently referenced.  If they are, then change the values.  If not then add these lines to the .htaccess file.

upload_max_filesize=50MB
post_max_size=50MB

The 50MB value in the example can be changed to suit your needs.  However, leave the value reasonable to avoid files that are “too large”.  Edit the value then save the file.  Finish by restarting the web server.  The next time a file is uploaded the new value will be reflected.

After you change the .htaccess or php.ini file restart the Apache web server.  Then the new file limit will be picked up by WordPress and applied to uploads moving forward.


 

Further Reading

Google is a great source of configuration tips and details.  However, we recommend you go to the source for PHP information.

http://php.net/manual/en/configuration.file.php

 

[sgmb id=”1″]

Rob Broadhead

Rob is a founder of, and frequent contributor to, Develpreneur. This includes the Building Better Developers podcast. He is also a lifetime learner as a developer, designer, and manager of software solutions. Rob is the founder of RB Consulting and has managed to author a book about his family experiences and a few about becoming a better developer. In his free time, he stays busy raising five children (although they have grown into adults). When he has a chance to breathe, he is on the ice playing hockey to relax or working on his ballroom dance skills.

Leave a Reply