【问题标题】:After deploying CakePHP3 application to Ubuntu server, all assets return 404 response将 CakePHP3 应用程序部署到 Ubuntu 服务器后,所有资产返回 404 响应
【发布时间】:2016-07-28 18:43:58
【问题描述】:

当我使用 git push 将我的 CakePHP3 应用程序部署到 Ubuntu 服务器的 var/www/html/{project_name} 目录时,webroot 文件夹中的所有资产(例如图像、css 文件、javascript 等)都没有加载。他们返回 404 响应。

这是我在webroot 目录中的.htaccess 文件:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteBase /
   RewriteRule    ^$    /    [L]
   RewriteRule    (.*) /$1    [L]
   AllowOverride All
</IfModule>

这是我在根目录中的.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
</IfModule>


<IfModule mod_rewrite.c>
    RewriteEngine On
    ReWriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

【问题讨论】:

  • 您确定 modrewrite 工作正常吗?日志文件说明了什么?
  • 服务器是否开启了模组重写功能?
  • @FrankerZ 在哪里可以查看日志?
  • 检查访问日志和错误日志的写入位置(在您的 apache 配置文件中)
  • @mcgowan.b 我刚刚使用了a2enmod rewrite 命令,现在我的页面根本没有加载,它说404 Not Found The requested URL /webroot/index.php was not found on this server. 顺便说一句,在同一台服务器上,cakephp2 项目运行得很好。跨度>

标签: php .htaccess cakephp cakephp-3.0 cakephp-3.x


【解决方案1】:

我通过从根项目目录运行composer install 解决了这个问题。

请注意,如果您的服务器为您的应用程序使用 PHP7 而不是 PHP5,您应该安装通用包而不是丢弃 PHP5 包。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-31
    • 2020-01-05
    • 1970-01-01
    • 2016-04-30
    • 2020-11-14
    • 1970-01-01
    • 2013-11-28
    • 1970-01-01
    相关资源
    最近更新 更多