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

AWS Amazon Linux上Apache部署Laravel路由报404错误求助

Laravel部署到AWS EC2 Amazon Linux 2 404问题排查方向
  • 修正访问路径
    你的DocumentRoot已设置为/var/www/html/myfolder/public,Apache根目录直接指向Laravel的public目录,访问时无需添加/myfolder。正确地址应为http://3.xxx.xxx.xxx/login,而非http://3.xxx.xxx.xxx/myfolder/login。

  • 启用mod_rewrite模块
    Amazon Linux 2的httpd默认未开启rewrite模块,这是Laravel路由正常工作的必要条件:

    1. 编辑/etc/httpd/conf.modules.d/00-base.conf,确保LoadModule rewrite_module modules/mod_rewrite.so未被注释(移除开头的#)。
    2. 重启httpd服务:sudo systemctl restart httpd
  • 修复文件权限
    Laravel需要storage和bootstrap/cache目录具备写入权限,执行以下命令:

    sudo chown -R apache:apache /var/www/html/myfolder
    sudo chmod -R 755 /var/www/html/myfolder/storage /var/www/html/myfolder/bootstrap/cache
    
  • 清除Laravel缓存
    部署后本地缓存可能与服务器环境冲突,运行以下命令清除缓存:

    cd /var/www/html/myfolder
    php artisan config:clear
    php artisan route:clear
    php artisan cache:clear
    
  • 检查Apache错误日志
    查看/var/log/httpd/error_log文件,里面会记录具体错误详情,比如路由解析失败、文件权限问题等,帮助定位根本原因。

  • 优化httpd.conf配置
    你的配置中Order allow,deny和allow from all是Apache 2.2语法,在Amazon Linux 2默认的Apache 2.4中已被Require all granted替代,虽兼容但可移除这两行避免潜在冲突:
    修改后的目录配置:

    <Directory /var/www/html/myfolder/public>
      Options FollowSymLinks Indexes MultiViews
      AllowOverride All
      Require all granted
    </Directory>
    

    修改后重启httpd服务。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 11:03:24