0
有人请赐教我在symfony中导致这个问题的原因以及如何解决它。哎呀!发生错误服务器返回“404未找到”。 Symfony
糟糕!发生错误服务器返回“404未找到”。
我只是symfony和cpanel的新手。
我刚刚从我的电脑(本地主机)上传我的工作SF应用程序到我的服务器或CPANEL
。 CPanel没有SSH access
,所以我使用FTP来上传所有目录。这样的文件的目录。
家/ swipecom
- 缓存
- 接触(其中SF目录居住)
- 的public_html(/ WEB唯一SF目录)
- VAR
- 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”。
东西坏了。当发生此 错误时,请让我们知道您在做什么。我们会尽快解决它。对不起,任何 造成的不便。
UPDATE
的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>
它看起来的工作,你注册到您的应用程序的任何路线? –
感谢您的评论,我在上面添加了我的路由。 – phpmeter
上传之前,您是否生成了生产缓存?如果是这样,请更改新的AppKernel('prod',false);到新的AppKernel('prod',true);以获得更好的错误信息。并检查您的主机是否有关于symfony的任何指示。经常有目录权限问题。 – Cerad