K. Weber
K. Weber

Reputation: 2773

Symfony2: jumping to production env is failing

Deployment into production environment is failing, I see a blank page and no log in app/log/prod.log.

I warmed up the prod cache and gave ownership of cahce dirs to www-data, there no php logging either, but this may be an administration error, I asked for it to be checked as I don't have access to it.

I changed my htaccess to omit app_dev.php and consider app.php, this is my .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>

Any clues?

Upvotes: 1

Views: 1595

Answers (2)

polpoul
polpoul

Reputation: 1

Is your database schema up to date ?

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

I experimented two times a similar situation and solved it the same way :

I had a work in progress in another bundle of the same project with no interaction with the part where that bug occured. Actually, i had not updated my database schema.

hope this helps

Upvotes: 0

Sybio
Sybio

Reputation: 8645

This is a supposition but if your dev environment works, and not your prod (on the same project & machine), this is because you forgot to add "umask(0000);" in web/app.php.

PHP Fatal error: require(): Failed opening required '/var/www/symfony/app/cache/prod/doctrine/orm/Proxies/_CG_MyProjectPanelBundleEn‌​tityAlgoritmo.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/symfony/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyF‌​actory.php on line 165

This is clearly a problem of rights and ownership of folders app/cache (and app/logs).

I gave ownership of cahce dirs to www-data

Depending on the fact you are using ACL, you mustn't do that, check the documentation. There are many solutions to fix this problem, explained in the grey frame.

To fix your problem if you don't use ACL, I think the easily way is to add "umask(0000);" in app.php (as you probably did in app_dev.php), at the beginning of your file and just after "use" declarations. (See "3. Without using ACL" in the grey frame). Otherwise, read the other instructions of the grey frame.

Now the framework will be able to write inside cache folder in the future. But if you don't use ACL, you need additionally to correct your current app/cache and app/logs folder configuration :

Considering your username is "user", say in root that the user "user" of usergroup "user" (usually the same as the username on a Linux machine) is the owner of these folders (and subfolders / files) :

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

Then clear these folders to be sure there are not broken or missing files (as "user") :

rm app/cache/* app/logs/*

Give 777 rights to the folders so that the framework will be able to write inside :

chmod 777 -R app/cache app/logs

In addition, even you probably did it, check that your app/console file has umask(0000); uncommented, because if you miss it the symfony console will write files as www-data, and you could not read cache file folder (you'll have the same error) !

Upvotes: 2

Related Questions