4

我已将 Symfony2 项目部署到我的开发服务器并希望运行开发环境。

如果我使用 /app.php,一切都运行良好,但如果我尝试 app_dev.php,我会收到 404 错误:

在此服务器上未找到请求的 URL /app_dev.php。

下面是我的 .htaccess 文件的副本:

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # Explicitly disable rewriting for front controllers
    RewriteRule ^app_dev.php - [L]
    RewriteRule ^app.php - [L]

    RewriteCond %{REQUEST_FILENAME} !-f

    # Change below before deploying to production
    #RewriteRule ^(.*)$ app.php [QSA,L]
    RewriteRule ^(.*)$ app_dev.php [QSA,L]
</IfModule>

它在我的本地机器上运行良好,只是在我的开发服务器上运行良好,有什么想法吗?

我的 /cache 和 /logs 目录都具有 777 权限,并由 www-data 拥有:

drwxrwxrwx+ 4 www-data www-data 4096 Mar 15 11:46 cache
drwxrwxrwx+ 2 www-data www-data 4096 Mar 15 11:05 logs

这些目录中的 dev 和 prod 完全相同。

4

1 回答 1

7

检查您的 app_dev.php,它有一个限制,即拒绝从服务器本身以外的其他计算机访问开发环境。

这是出于安全原因,如果您部署到生产服务器并且用户可以访问 dev env,那么他/她可以对您的应用程序了解很多。

// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
    || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
    || !in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))
) {
    header('HTTP/1.0 403 Forbidden');
    exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}

您必须将您的 IP 添加到该阵列,或删除整个事情(我不会推荐)。

永远记住将 dev 变量传递给 AppKernel。$kernel = new AppKernel('dev', true);

于 2013-03-15T12:47:32.353 回答