The error message “the uploaded file exceeds the upload_max_filesize
directive in php.ini” means that the file you are trying to upload is larger than the maximum file size allowed by your server. To fix this error, you need to increase the maximum file size allowed in your PHP configuration file.
In this article, we will learn how to fix this error by adjusting the upload_max_filesize variable in php.ini
.
Other Error Fixes
- How to Fix a 408 Request Timeout Error
- How to Fix 403 Forbidden Error in NGINX Ubuntu
- Fix 413 Request Entity Too Large Error on Nginx & Apache
- Error Establishing a Database Connection in WordPress Fix
- Fix 502 Bad Gateway Nginx Error in Ubuntu – 4 Simple Steps
- Fix 504 Gateway Timeout Nginx Error – 5 Simple Steps
- PHP5-FPM 502 Bad Gateway Error (connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory)
Prerequisites
- A working WordPress installation
- Access to the server that hosts the WordPress installation
- Access to a file manager (or cPanel)
- A user account with
sudo
privileges - Access to a command line interface or terminal window
3 Simple Ways to Fix Uploaded File Exceeds upload_max_filesize error in WordPress
Method 1: Edit the .htaccess
File
Using cPanel
Open the cPanel and launch the file manager.
Navigate to the root folder of your website and edit the .htaccess
file.
Now, look for the php_value_upload_max_filesize
and increase its value to 256
. Which means you’re allowed to upload a file size of 256 MB.
php_value_upload_max_filesize 256M
The code snippet php_value_upload_max_filesize 256M
is used to increase the maximum file upload size in a PHP environment.
Save the changes and exit the file.
Using Command Line Interface (CLI)
If you find yourself comfortable using a terminal then this method is for you.
We will perform the same thing that we did earlier. But here, we will be using a command line interface to quickly make the required changes.
This option is for those who use Cloud Servers like Linode or Digital Ocean and don’t have access to the cPanel.
Here are the steps:
Log in to your server using SSH and navigate to the WordPress website directory by running the following command:
cd /path/to/wordpress
Now, open and edit the .htaccess file using your favourite editor. In my case, I prefer using the vim
editor.
To do that, run:
sudo vim .htaccess
Now, search for the php_value_upload_max_filesiz
e and increase its value to 256
.
Save the changes by pressing the ESC button on your keyboard, enter wq!
and hit enter or return button.
Method 2: Editing the wp-config.php File
You can also increase the maximum file upload size by tweaking the wp-config.php
file located in your root directory.
All you need to do is log in to the cPanel and access the public_html
directory.
Here, search for the wp-config.php
file and add the following line before the “That’s all, stop editing! Happy publishing” line:
@ini_set('upload_max_size' , '256M' );
The @ini_set()
function tells PHP to set the specified value for the specified ini
directive. In this case, we are setting the upload_max_filesize
directive to 256 megabytes.
Once you have added this code snippet to the wp-config.php file, you need to save the file and then upload it to your web server. Once the file has been uploaded, you should be able to upload files that are up to 256 megabytes in size.
It is important to note that this method of increasing the maximum file upload size is not always reliable. Some web hosting providers may not allow you to change the values of the upload_max_filesize
and post_max_size
directives in the wp-config.php
file.
If you are having problems increasing the maximum file upload size using this method, you may need to contact your web hosting provider for assistance.
Method 3. Updating php.ini to Fix the upload_max_filesize
Error
The upload_max_filesize
directive is defined in the php.ini
file. This directive specifies the maximum size of a file that can be uploaded to a web server. If you are trying to upload a file that is larger than the upload_max_filesize
directive, you will receive this error message.
The php.ini
file is a configuration file that contains all of the PHP-related variables. These variables control how PHP behaves.
In general, if you’re using shared hosting, all limits are at the maximum value. If the problem still persists, contact your web hosting provider to suggest you a solution for any such errors.
If you’re managing a VPS or dedicated cloud server, this is the fix you will ever need.
The location of PHP may vary depending on the Linux distribution and PHP version you’re using.
If you’re on Ubuntu and using the latest version of PHP i.e., PHP 8, navigate to the /etc/php/8.1/apache2/
or /etc/php/8.1/fpm/
directory if you’re using FastCGI Process Manager.
Now, edit the php.ini
file by running the following command:
sudo vim php.ini
Locate the upload_max_filesize
directive and change its value to 256
.
upload_max_filesize = 256M
Moreover, you would also want to adjust the following directives:
post_max_size = 256M memory_limit = 512M max_execution_time = 180
Conclusion
In this tutorial, you have learned three different ways to fix the uploaded file exceeds the upload_max_filesize
directive in php.ini
error in WordPress.
Here’s a quick recap:
- Editing the
.htaccess
File Using cPanel and Command Line Interface (CLI). - Editing the wp-config.php file using
@ini_set()
function. - Updating php.ini to Fix the
upload_max_filesize
Error
Easy, right? If you have any questions or suggestions, don’t hesitate to comment down below!