I'm facing an issue where I'm unable to upload files larger than ~32MB on my PHP application deployed on AWS Elastic Beanstalk. The error I'm seeing in the php-fpm/www-error.log is:
PHP Warning: POST Content-Length of XXXXXXXX bytes exceeds the limit of 33554432 bytes in Unknown on line 0
I tried increasing the upload_max_filesize and post_max_size in the /etc/php.ini file by SSH-ing into my EC2 instance and making the following changes:
sudo nano /etc/php.ini
I updated the following values:
upload_max_filesize = 100M
post_max_size = 100M
memory_limit = 512M
max_execution_time = 300
After restarting the Nginx and PHP-FPM services, I checked using a phpinfo() file to see if the changes were applied:
sudo nano /var/www/html/phpinfo.php
However, when I accessed phpinfo(), I noticed that post_max_size was still set to 32M, and the error persisted.
It seems like Elastic Beanstalk was overriding the php.ini settings, and I'm not sure how to permanently apply the changes to allow larger file uploads. Has anyone else experienced this issue or know how to fix it?
I found the solution, and it turns out that Elastic Beanstalk was indeed overriding the php.ini settings. Here's what I did to fix the issue:
Elastic Beanstalk can override PHP settings through environment configurations or .ebextensions files. In my case, even though I modified /etc/php.ini directly, the post_max_size was being reset by Elastic Beanstalk's configuration.
To permanently fix this issue, I had to create a configuration file inside .ebextensions directory that applies my desired PHP settings on every deployment.
Steps I followed:
In my project folder, I created a new configuration file (.ebextensions/php-settings.config).
files:
"/etc/php.d/custom.ini":
mode: "000644"
owner: root
group: root
content: |
upload_max_filesize = 100M
post_max_size = 100M
memory_limit = 512M
max_execution_time = 300
I deployed this change to Elastic Beanstalk using my usual deployment process. After deployment, these settings were applied correctly, and I confirmed the changes by checking the phpinfo() file again.
Now, post_max_size and upload_max_filesize were set to 100M, and the file upload issue was resolved.
Don't forget to restart Nginx and PHP-FPM for changes to take effect.
sudo systemctl restart nginx
sudo systemctl restart php-fpm
Why this worked:
Elastic Beanstalk sometimes overrides certain settings, especially related to PHP configuration. By creating an .ebextensions file, you ensure that your configuration is deployed correctly and consistently applied across all environments.
I hope this helps others facing the same issue.