繁体   English   中英

部署Symfony2项目时出现问题

[英]Problems deploying Symfony2 project

我在将symfony2项目部署到http://beachteamvandenbroecke-engels.be/遇到困难。

我无权访问服务器上的ssh,因此必须手动将项目文件夹复制到我的网站。
我已经导出了本地数据库并将其插入服务器中。
我已经更改了config/parameters.yml的设置。

但是现在,当我想访问http://beachteamvandenbroecke-engels.be/web/app_dev.php (尚未设置要重定向的.htaccess文件)时,出现以下错误:

You are not allowed to access this file. Check app_dev.php for more information.

在我的app_dev.php中:

<?php

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;

// If you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);

// 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.');
}

$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
Debug::enable();

require_once __DIR__.'/../app/AppKernel.php';

$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

我做错了什么?

正如评论所说

// 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地址是否被允许。 允许的IP包含在此数组array('127.0.0.1', 'fe80::1', '::1')

注意

在prod env中,您需要指向app.php而不是app_dev.php

编辑

为了切换到PROD env,请运行以下命令:

php app/console cache:warmup --env=prod --no-debug

--env=prod将提供指向app.php而不是app_dev.php

--no-debug将退出调试模式,因为它不会在浏览器中显示Symfony调试栏。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM