部署symfony2后获得500响应

时间:2017-05-26 18:19:01

标签: php apache .htaccess symfony

我一直在尝试在共享托管服务器上部署symfony2,但我不断获得500 response

web/目录下的所有文件都已放入public_html目录。

其他目录[appbinsrcvendor]已经放在一个更高的级别。

我的目录结构如下所示:

| -- /app
| -- /bin
| -- /src
| -- /vendor
| -- /public_html

在将文件上传到服务器之前,我确实手动清除了缓存。

app.php

<?php

use Symfony\Component\HttpFoundation\Request;
use Sonata\PageBundle\Request\RequestFactory;
/** @var \Composer\Autoload\ClassLoader $loader */
$loader = require __DIR__.'/../app/autoload.php';
include_once __DIR__.'/../app/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);

的.htaccess

DirectoryIndex app.php
#DirectoryIndex app_dev.php

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    #RewriteRule ^app_dev\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]
    RewriteRule ^app\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]


    RewriteCond %{REQUEST_FILENAME} -f
    #RewriteRule ^(.*)$ app_dev.php [QSA,L]
    RewriteRule ^(.*)$ app.php [QSA,L]

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]
    #RewriteRule .? %{ENV:BASE}app_dev.php [L]
    RewriteRule .? %{ENV:BASE}app.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 302 ^/$ /app.php/
        # RedirectTemp cannot be used instead
    </IfModule>
</IfModule>

composer.json

 "extra": {
        "symfony-app-dir": "app",

        "symfony-web-dir": "public_html",

        "symfony-assets-install": "symlink",
        "incenteev-parameters": {
            "file": "app/config/parameters.yml"
        },
        "branch-alias": {
            "dev-master": "2.8-dev"
        }
    }

的web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="web directory">
                    <match url=".*" ignoreCase="false" />
                    <action type="Rewrite" url="public_html/{R:0}" appendQueryString="true" />
                </rule>
                <rule name="app_php handling" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/public_html/app.php" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

2 个答案:

答案 0 :(得分:0)

当您的cache目录不可写时,这是相当常见的。

chmod 0755 /path/to/cache

或在某些情况下甚至:

chmod 0777 /path/to/cache

答案 1 :(得分:0)

这看起来像您的服务器无法找到您的文件。 不确定IIS,但你错过了一些规则。看看https://gist.github.com/nurbek-ab/9c2997441fcaa2e52b0a

在nginx中它是

root / var / www / project / web;

location / {
    # try to serve file directly, fallback to app.php
    try_files $uri /app.php$is_args$args;
}