How to Fix ‘The uploaded file exceeds the upload_max_filesize directive in php.ini’ in WordPress

 

 

Installing WordPress is a fairly easy task and it only takes a few minutes. After installing WordPress, you may want to change the default theme and install a new one, install some WordPress plugins, create new posts and upload image files etc. When installing a WordPress theme, plugin or uploading a image using the WordPress back-end, you may receive the following error message in your web browser:

‘The uploaded file exceeds the upload_max_filesize directive in php.ini’

There is no need to panic, because the solution of this problem is quick and easy.

There are four simple ways you can fix this problem:

  1. Edit the .htaccess file located in the document root directory of the WordPress installation.
    Locate the .htaccess file, and edit it using your favorite editor (vi,nano,vim etc.), and add or modify the following line:

    php_value upload_max_filesize 100M

    Replace ‘100’ with the maximum upload file size (in megabytes) that you want to set on your WordPress installation.

    You may also want to adjust some other PHP settings, like:
    – memory_limit (maximum amount of memory a script may consume);
    – post_max_size (the maximum size for all POST body data);
    – max_execution_time (the maximum time in seconds a script is allowed to run before it is terminated by the parser);
    – max_input_time (the maximum time in seconds a script is allowed to parse input data, like POST and GET).
    If so, add or modify the following lines too:

    php_value memory_limit 256M
    php_value post_max_size 32M
    php_value max_execution_time 600
    php_value max_input_time 900

    Get optimized, fully managed WordPress hosting from us and we’ll configure and fix your WordPress for free

  2. Edit the ‘functions.php’ file located in the active theme directory (wp-content/themes/), or the ‘wp-config.php’ file located in the document root directory of the WordPress installation.
    Add the following line to the wp-config.php file:

    @ini_set( 'upload_max_size' , '100M' );
  3. Edit the main PHP configuration file.
    Use the following command to locate the main PHP configuration file on your server, e.g.:

    # php -i | grep -i php.ini
    Configuration File (php.ini) Path => /etc/php/7.0/cli
    Loaded Configuration File => /etc/php/7.0/cli/php.ini

    Once you locate the main PHP configuration file, edit it and add or modify the following line:

    upload_max_filesize = 100M

    It is a good idea to modify these settings too:

    memory_limit = 256M
    post_max_size = 32M
    file_uploads = On
    max_execution_time = 600
    max_input_time = 900
    

    Do not forget to restart your web server for the changes to take effect.

  4. Create a local php.ini configuration file in the document root of the WordPress installation, ‘add upload_max_filesize = 100M’ to it, save the file thus override main php.ini configuration settings.
    Again, you need to restart your web server for the changes to take effect.

That is it. You should be able to install new WordPress theme, plugins, and upload image files now.

 

Source