【发布时间】:2017-04-15 12:03:47
【问题描述】:
谁能告诉我在symfony中导致这个问题的原因以及如何解决它。
哎呀!发生错误服务器返回“404 Not Found”。
我只是 symfony 和 cpanel 的新手。
我刚刚将我的工作 SF 应用程序从我的电脑 (localhost) 上传到我的服务器或CPANEL。 CPanel 没有SSH access,所以我使用 FTP 上传所有目录。文件目录如下。
主页/swipecom
- 缓存
- 非接触式(SF 目录所在的位置)
- public_html(/web 唯一的 SF 目录)
- 变量
- ssl
- tmp
- public_ftp
- 日志
我创建了.htaccess 到public_html 就像这样public_html/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
最后,我用类似这样的方式配置了app.php。
<?php
use Symfony\Component\HttpFoundation\Request;
/** @var \Composer\Autoload\ClassLoader $loader */
// $loader = require __DIR__.'/../app/autoload.php';
// include_once __DIR__.'/../var/bootstrap.php.cache';
$loader = require '/home2/swipecom/contactless/app/autoload.php';
include_once '/home2/swipecom/contactless/var/bootstrap.php.cache';
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
//$kernel = new AppCache($kernel);
// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
//Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
当我尝试像 www.domain.com 这样访问应用程序时,这是我收到的回复。
哎呀!发生错误
服务器返回“404 Not Found”。
有些东西坏了。请让我们知道您在此期间在做什么 错误发生。我们会尽快修复它。对不起任何 造成的不便。
更新
routing.yml
route_frontend:
resource: "@SwipeBundle/Resources/config/routing_frontend.yml"
route_backend:
resource: "@SwipeBundle/Resources/config/routing_backend.yml"
route_security:
resource: "@SwipeBundle/Resources/config/routing_security.yml"
routing_dev.yml
_wdt:
resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"
prefix: /_wdt
_profiler:
resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
prefix: /_profiler
_errors:
resource: "@TwigBundle/Resources/config/routing/errors.xml"
prefix: /_error
_main:
resource: routing.yml
AppKernel.php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
// new SunCat\MobileDetectBundle\MobileDetectBundle(),
new SwipeBundle\SwipeBundle(),
];
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
public function getRootDir()
{
return __DIR__;
}
public function getCacheDir()
{
return dirname(__DIR__).'/var/cache/'.$this->getEnvironment();
}
public function getLogDir()
{
return dirname(__DIR__).'/var/logs';
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
}
}
.htaccess 在web 目录中
DirectoryIndex app.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>
【问题讨论】:
-
它看起来工作正常,你有注册到你的应用程序的路由吗?
-
感谢您的评论,我在上面添加了我的路由。
-
上传前是否生成了生产缓存?如果是这样,请更改 new AppKernel('prod', false);到新的 AppKernel('prod', true);可能会得到更好的错误信息。并检查您的主机是否有任何关于 symfony 的说明。经常会出现目录权限问题。
-
在上传之前我只是运行这个命令
./bin/console cache:clear --env=prod & ./bin/console cache:clear --env=dev,