You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS Elastic Beanstalk部署PHP应用无法上传32MB以上文件求助

解决AWS Elastic Beanstalk PHP应用大文件上传限制问题

问题说明

部署在AWS Elastic Beanstalk的PHP应用无法上传大于32MB的文件,php-fpm日志中出现报错:

PHP Warning: POST Content-Length of XXXXXXXX bytes exceeds the limit of 33554432 bytes in Unknown on line 0

手动修改EC2实例的/etc/php.ini配置(调整upload_max_filesize、post_max_size等参数)并重启服务后,配置未生效——因为Elastic Beanstalk会自动覆盖实例上的默认配置,手动修改无法永久保留。

永久解决方法

Elastic Beanstalk要求通过项目内的.ebextensions配置文件来管理PHP参数,确保部署、扩容实例时配置自动生效。

步骤1:创建.ebextensions目录

在项目根目录下创建.ebextensions文件夹:

mkdir .ebextensions

步骤2:编写PHP配置文件

在.ebextensions目录下新建php-upload-limits.config文件,写入以下内容:

files:
  "/etc/php.d/99-upload-limits.ini":
    mode: "000644"
    owner: root
    group: root
    content: |
      upload_max_filesize = 100M
      post_max_size = 100M
      memory_limit = 512M
      max_execution_time = 300
commands:
  restart_php_fpm:
    command: "systemctl restart php-fpm"
    ignoreErrors: true
  • 自定义的.ini文件放在/etc/php.d/目录下,优先级高于默认php.ini,不会被覆盖
  • 99-前缀确保该文件最后加载,覆盖其他同类型配置
  • 重启PHP-FPM命令确保配置立即生效

步骤3:部署更新后的代码

将包含.ebextensions文件夹的项目代码重新部署到Elastic Beanstalk:

  • 使用EB CLI:执行eb deploy
  • 使用控制台:上传包含.ebextensions的代码包完成重新部署

步骤4:验证配置

部署完成后,通过phpinfo()查看参数,post_max_size和upload_max_filesize应已更新为100M。

额外:Nginx配置适配(可选)

如果使用Nginx作为反向代理,需要同步调整Nginx的请求体大小限制,避免Nginx先拦截大文件请求。在同一个.config文件中添加以下内容:

files:
  # 保留之前的PHP配置部分...
  "/etc/nginx/conf.d/00-client-max-body-size.conf":
    mode: "000644"
    owner: root
    group: root
    content: |
      client_max_body_size 100M;
commands:
  # 保留之前的重启命令...
  restart_nginx:
    command: "systemctl restart nginx"
    ignoreErrors: true

内容的提问来源于stack exchange,提问作者Isuru

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 23:51:12