When I try to upload WordPress files larger than 2 MB, I receive the following error message: "the uploaded file exceeds the upload_max_filesize directive in php.ini."

How can I resolve this error?

The default PHP configuration on an Amazon Elastic Compute Cloud (Amazon EC2) instance doesn't allow you to upload WordPress files larger than 2 MB. To upload files larger than 2 MB, change the default value of the upload_max_filesize parameter in the /etc/php.ini file.

Note: M and MB are equivalent expressions for megabyte. For example, 2M is equal to 2 MB. However, use only M in your configuration file, as MB is not valid.

Change the upload file size for a single Amazon EC2 instance running a LAMP stack

1.    To open the /etc/php.ini file with the vi editor, run the following command:

$ sudo vi /etc/php.ini

Note: The /etc/php.ini file name or path can vary depending on your version of PHP or the Amazon Machine Image (AMI) that you're using.

2.    In the vi editor, change the value of the upload_max_filesize parameter to a larger size than 2 MB, and then save the file.

Note: To adjust php.ini parameters such as memory_limit, see the php.ini directives for post_max_size.

3.    To restart the Apache server gracefully, run the appropriate command for your environment.

For Amazon Linux:

$ sudo service httpd graceful

For Amazon Linux 2:

$ sudo service httpd reload

Note: The /etc/php.ini file name or path can vary depending on your version of PHP or the AMI that you're using. The command to restart the Apache server can also vary if you are using a distribution other than Amazon Linux AMI.

WordPress limits the memory of its PHP processes by default. To modify WP_MEMORY_LIMIT or WP_MAX_MEMORY_LIMIT in the wp-config.php file, see Increasing memory allocated to PHP.

Update the upload file size for an AWS Elastic Beanstalk environment running a PHP solution stack

To increase the file size across all instances, complete the following steps to update the underlying AMI.

1.    In a code editor, create a new file named change_upload_size.config, and then add the following code to the file:

  files:
      "/etc/php.d/99uploadsize.ini":
          mode: "000644"
          owner: root
          group: root
          content: |
              upload_max_filesize = 100M
              post_max_size = 100M
  commands:
      remove_old_ini:
          command: "rm -f /etc/php.d/99uploadsize.ini.bak"

Note: In this example, the value of the post_max_size parameter is updated from the default 8M to 100M.

To adjust php.ini parameters such as memory_limit, see the php.ini directives for post_max_size. The maximum memory_limit value in Elastic Beanstalk is 256M.

2.    In the root of your application source bundle, create a new directory called .ebextensions, and then move the change_upload_size.config file to the .ebextensions directory.

If the .ebextensions directory is already inside your application source bundle, keep the change_upload_size.config file in the .ebextensions directory with other .config files. The directory structure should be similar to the following example:

├── wp-site.zip/ 
    ├── .ebextensions/
         ├── change_upload_size.config
    ├── wp-content/
    ├── wp-includes/
    ├── wp-admin/
    ├── LICENSE
    ├── README.md
    ├── index.php
    ├── license.txt
    ├── readme.html
    ├── ...
    ├── ...
    ├── ...
    ├── ...
    ├── wp-settings.php
    ├── wp-signup.php
    ├── wp-trackback.php
    └── xmlrpc.php

3.    Open the Elastic Beanstalk console, and then create a zip archive of your application source bundle.

4.    To upload your code to an existing Elastic Beanstalk environment, choose your environment, and then choose Upload and Deploy.

Note: To deploy your code in a new Elastic Beanstalk environment, see Creating an AWS Elastic Beanstalk Environment.

WordPress limits the memory of its PHP processes by default. To modify WP_MEMORY_LIMIT or WP_MAX_MEMORY_LIMIT in the wp-config.php file, see Increasing memory allocated to PHP.

If the error message does not go away after you upload the .ebextensions file, use a YAML validator to check for white space errors in your code. Also, consider using the remove_old_ini command to remove unnecessary backup files. For more information, see Extending php.ini.


Did this page help you? Yes | No

Back to the AWS Support Knowledge Center

Need help? Visit the AWS Support Center

Published: 2016-12-27

Updated: 2019-01-16