symfony2 - how to switch from “dev” to “prod”?

后端 未结 6 2235
再見小時候
再見小時候 2020-12-04 10:53

I downloaded symfony2 and I am able to run it starting from app_dev.php.

But when I start from app.php, then I get an error page 404.

app.php though is of co

相关标签:
6条回答
  • 2020-12-04 11:22

    Your problem is related to the cache of Symfony2. I had the same problems. Try this:

    • sudo php app/console cache:clear --env=prod --no-debug
    • sudo chmod 777 -R ../sf2/ (sf2) is the main directory of my proyect

    You're done.

    0 讨论(0)
  • 2020-12-04 11:29

    I just wanted to integrate a couple of tips for this kind of problem since I faced it nowadays with a new fresh Symfony2 installation.

    As a fresh installation you normally get AppBundle under /src/AppBundle together with AcmeDemoBundle under /src/Acme/DemoBundle

    If you want to run AcmeDemoBundle on app_dev and, in the meanwhile, have an application ( i.e. AppBundle provided with fresh installation ) on app.php ( and avoid 404 ) you can also do something like that:

    in /app/config/routing_dev.yml comment the following rows ( if you have them ):

    _main:
        resource: routing.yml
    

    in /app/config/routing.yml add a new route ( if you don't have )

    index:
        pattern:  /
        defaults: { _controller: AppBundle:Default:index }
    

    then empty cache like already advised by the others and test the application on


    1) http:// your_application_path/web/


    2) http:// your_application_path/web/app_dev.php

    If everything is fine on the first one you should get a white page with a string "Homepage." ( to edit this one go in /app/Resources/views/default/index.html.twig... Layout for this one is base.html.twig ) and, on the second one you should get the DemoBundle provided by Symfony2.

    Hope it helps!

    0 讨论(0)
  • 2020-12-04 11:31

    I fixed it with just letting the web-server account (i.e. 'master-chef' own the /Symfony2/app/cache/prod directory. The command as below:

    $sudo chown master-chef -R /var/www/Symfony2/app/cache/prod
    
    0 讨论(0)
  • 2020-12-04 11:32

    In your "web/app.php" file

     $kernel = new AppKernel('prod', false);
    

    Change the value to "true".

     $kernel = new AppKernel('prod', true);
    

    Now you can load the application in production mode.

    0 讨论(0)
  • 2020-12-04 11:33

    Change the owner instead.
    sudo chown www-data:www-data -R app/cache
    sudo chown www-data:www-data -R app/logs

    Thats letting the browser own the folders. the syntax is:
    chown <USER>:<GROUP> <SWITCH> <DIRECTORY>

    0 讨论(0)
  • 2020-12-04 11:35

    By default, Symfony 2 is delivered with a demo bundle which is just accessible from the development environment.

    The production environment doesn't contain any route, so it's normal you get a 404 error page.

    EDIT :

    Are you sure your bundle is enable in the AppKernel.php ?

    If yes, clear the cache with the following command : ./app/console cache:clear

    Check if the route is enable with the following command : ./app/console router:debug

    0 讨论(0)
提交回复
热议问题