When deploying PHP applications on AWS Elastic Beanstalk, you might need to modify PHP configuration settings like upload_max_filesize
or post_max_size
. However, these settings can't be changed through the standard .ebextensions
option_settings because the aws:elasticbeanstalk:container:php:phpini
namespace doesn't support extension.
The most reliable method is to create a custom php.ini
file and deploy it during the instance setup phase. Here's how:
files:
"/etc/php.d/my_settings.ini":
mode: "000644"
owner: root
group: root
content: |
upload_max_filesize = 64M
post_max_size = 64M
memory_limit = 128M
max_execution_time = 300
For some PHP settings, you can use .htaccess
in your application root:
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value memory_limit 128M
After deployment, create a PHP info file to verify your settings:
<?php
phpinfo();
?>
For different PHP versions, you might need to place the ini file in different locations:
commands:
create_php_ini:
command: |
if [ -d "/etc/php/7.4/apache2/conf.d" ]; then
echo "upload_max_filesize = 64M" > /etc/php/7.4/apache2/conf.d/my_settings.ini
elif [ -d "/etc/php5/apache2/conf.d" ]; then
echo "upload_max_filesize = 64M" > /etc/php5/apache2/conf.d/my_settings.ini
fi
- Always test configuration changes in a staging environment first
- Remember that some PHP settings can only be changed in php.ini
- After modifying php.ini, you'll need to restart your web server
When deploying PHP applications on AWS Elastic Beanstalk, you'll encounter scenarios where standard PHP configuration options like upload_max_filesize
and post_max_size
can't be modified through the usual .ebextensions
mechanism. This occurs because these directives belong to the non-extensible aws:elasticbeanstalk:container:php:phpini
namespace.
The most reliable method involves creating a custom .user.ini
file that Elastic Beanstalk will merge with the main PHP configuration:
files:
"/etc/php.d/custom.ini":
mode: "000644"
owner: root
group: root
content: |
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300
memory_limit = 128M
For applications using Apache, you can also configure these settings in your document root's .htaccess
file:
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
To confirm your changes took effect, create a simple PHP info script:
<?php
phpinfo();
?>
Deploy this file temporarily and check that your custom values appear in the PHP configuration section.
- Changes require an environment rebuild for
.user.ini
modifications - Always test changes in a staging environment first
- Consider EC2 instance type when increasing memory limits
- Monitor ELB timeout settings which may also affect large uploads