Symfony2:跳到生产环境失败了

时间:2013-06-01 23:36:56

标签: symfony deployment

部署到生产环境失败,我看到一个空白页面,没有登录app / log / prod.log。

我预热了prod缓存,并将cahce dirs的所有权交给 www-data ,也没有php日志记录,但这可能是一个管理错误,我要求它被检查为我无法访问它。

我改变了我的htaccess以省略app_dev.php并考虑app.php,这是我的.htaccess:

# Use the front controller as index file. It serves as fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# startpage (path "/") because otherwise Apache will apply the rewritting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex app.php
#DirectoryIndex app_dev.php

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Redirect to URI without front controller to prevent duplicate content
    # (with and without `/app.php`). Only do this redirect on the initial
    # rewrite by Apache and not on subsequent cycles. Otherwise we would get an
    # endless redirect loop (request -> rewrite to front controller ->
    # redirect -> request -> ...).
    # So in case you get a "too many redirects" error or you always get redirected
    # to the startpage because your Apache does not expose the REDIRECT_STATUS
    # environment variable, you have 2 choices:
    # - disable this feature by commenting the following 2 lines or
    # - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
    #   following RewriteCond (best solution)
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    #RewriteRule ^app_dev\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]
    RewriteRule ^app\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]

    # If the requested filename exists, simply serve it.
    # We only want to let Apache serve files and not directories.
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]


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

    # The following rewrites all other queries to the front controller. The
    # condition ensures that if you are using Apache aliases to do mass virtual
    # hosting, the base path will be prepended to allow proper resolution of the
    # app.php file; it will work in non-aliased environments as well, providing
    # a safe, one-size fits all solution.
    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>
        # When mod_rewrite is not available, we instruct a temporary redirect of
        # the startpage to the front controller explicitly so that the website
        # and the generated links can still be used.
        #RedirectMatch 302 ^/$ /app_dev.php/
        RedirectMatch 302 ^/$ /app.php/
        # RedirectTemp cannot be used instead
    </IfModule>
</IfModule>

任何线索?

2 个答案:

答案 0 :(得分:2)

这是一个假设,但如果您的开发环境有效,而不是您的产品(在同一个项目和机器上),这是因为您忘记添加&#34; umask(0000);&#34;在web / app.php。

  

PHP致命错误:require():需要打开失败   &#39; /无功/网络/ symfony的/应用/高速缓存/ PROD /教义/ ORM /代理/ _ CG _MyProjectPanelBundleEn tityAlgoritmo.php&#39;   (include_path =&#39;。:/ usr / share / php:/ usr / share / pear&#39;)in   在/ var / WWW / symfony中/供应商/教义/ common / lib目录/教义/通用/代理/ AbstractProxyF actory.php   在第165行

这显然是文件夹app / cache(和app / logs)的权利和所有权问题。

  

我将cahce dirs的所有权归属于www-data

根据您使用ACL的事实,您不能这样做,请检查documentation。解决这个问题有很多解决方案,在灰框中有解释。

要解决您的问题,如果您不使用ACL,我认为轻松的方法是添加&#34; umask(0000); &#34;在 app.php (就像你在app_dev.php中所做的那样),在文件的开头和#34;之后使用&#34;声明。 (参见&#34; 3.不使用ACL&#34;在灰色框中)。否则,请阅读灰框的其他说明。

现在框架将来可以在缓存文件夹中写入。 但如果您不使用ACL ,则还需要更正当前的应用/缓存和应用/日志文件夹配置:

考虑到您的用户名是&#34;用户&#34;,请在root中说用户&#34; user&#34;用户组&#34;用户&#34; (通常与Linux机器上的用户名相同)是这些文件夹(和子文件夹/文件)的所有者:

su chown user.user -R app/cache app/logs

然后清除这些文件夹以确保没有损坏或丢失的文件(&#34;用户&#34;):

rm app/cache/* app/logs/*

授予文件夹777权限,以便框架能够在内部写入:

chmod 777 -R app/cache app/logs

此外,即使你可能做到了,检查你的app / console文件是否有umask(0000);取消注释,因为如果你错过它,symfony控制台会将文件写为www-data,你无法读取缓存文件夹(你会有同样的错误)!

答案 1 :(得分:0)

您的数据库架构是最新的吗?

php app/console doctrine:schema:update --dump-sql

我尝试了两次相似的情况并以同样的方式解决了它:

我在同一个项目的另一个捆绑包中进行了一项工作,但没有与发生该错误的部分进行交互。实际上,我没有更新我的数据库架构。

希望这会有所帮助