When I upload WordPress files that are larger than 2 MB to my AWS Elastic Beanstalk environment, I receive the following error: "The uploaded file exceeds the upload_max_filesize directive in php.ini."
Short description
The default PHP configuration on an Amazon Elastic Compute Cloud (Amazon EC2) instance doesn't allow you to upload WordPress files that are larger than 2 MB. To upload files that are larger than 2 MB, change the default value of the upload_max_filesize parameter in the /etc/php.ini file.
Important: M and MB are equivalent expressions for megabyte. For example, 2 M is equal to 2 MB. Because MB isn't valid in a configuration file, use only M.
Resolution
Choose the resolution that applies to your solution stack.
Update the upload file size for an Elastic Beanstalk environment that runs a PHP solution stack
To increase the file size across all instances, update the Amazon Machine Image (AMI) that you use.
Complete the following steps:
- In a code editor, create a new file that's 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 the preceding example, the value of the post_max_size parameter is updated from the default 32 M to 100 M.
To modify 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 256 M.
- In the root of your application source bundle, create a new directory that's named .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, then keep the change_upload_size.config file in the .ebextensions directory with the other .config files.
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
Important: For Amazon Linux 2 platforms that are based on Elastic Beanstalk, change the file name 99uploadsize.ini to z99uploadsize.ini. To allow the new PHP settings to override the defaults, change the file name everywhere in the .ebextension.
- Open the Elastic Beanstalk console, and then create a .zip archive of your application source bundle.
- 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 Elastic Beanstalk environment.
If the error message remains after you upload the .ebextensions file, then use a YAML validator to check for white space errors in your code. Also, run the remove_old_ini command to remove unnecessary backup files. For more information, see Extending php.ini.
Change the upload file size for a single instance that runs a LAMP stack
Complete the following steps:
- To use the vi editor to open the /etc/php.ini file, 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 AMI that you use.
- 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 modify php.ini parameters, such as memory_limit, see the php.ini directives for post_max_size. For more information, see post_max_size on the PHP website.
- To gracefully restart the Apache server, run the following command for your environment.
Amazon Linux:
$ sudo service httpd graceful
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 use. If you use a distribution other than Amazon Linux AMI, then the command to restart the Apache server can also vary. WordPress limits the memory of its PHP processes by default.
Related information
Advanced environment customization with configuration files (.ebextensions)
Deploying a high-availability WordPress website with an external Amazon Relational Database Service (Amazon RDS) database to Elastic Beanstalk
Host a WordPress blog on Amazon Linux 2
Description of core php.ini directives on the PHP website