34

Can someone help me to move my Symfony 2 application into production mode?

Currently, the application is running properly in /app_dev.php.

I'm googling, but I'm not finding a definite guide for deployment in Symfony 2.

nbro
  • 15,395
  • 32
  • 113
  • 196
Noor
  • 19,638
  • 38
  • 136
  • 254

5 Answers5

55

Couple more things to consider:

php app/console cache:clear --env=prod --no-debug
php app/console assets:install web_directory
php app/console assetic:dump web_directory

You might also run into permission issues with the cache directory. I would actually first make sure everything works in development mode on the server before switching to production mode. And if all you get is blank screens in production mode then set debug to true. And of course know how to check your error logs.

Cerad
  • 48,157
  • 8
  • 90
  • 92
  • The Symfony logs are in app/logs. The web server depends on the server and how it is configured so can't really help there. – Cerad Feb 14 '12 at 14:15
  • you answer was THE answer, thanks, by the way, all those who'll use this answer, everytime u change something in your scripts, do this, php app/console cache:clear --env=prod --no-debug, also sometime u need to change permission, so do a chown !! – Noor Feb 15 '12 at 17:05
  • 11
    This answer isn't standalone. Can you include the relevant bits of the other answer rather than start with "Couple more things"? E.g. "Configure rewrite rules to use `app.php`, not `app_dev.php`, remove `app_dev.php`" – rjmunro Apr 11 '13 at 16:40
  • 1
    Shouldn't you also run the `php app/console cache:warmup --env=prod` command? – SirDerpington Apr 13 '14 at 17:33
11

Moving Symfony2 to production means :

access the application through : app.php/

Test dev bundles won't be loaded since there is a condition into the AppKernel.php when you use app.php. If you want to unload bundle that should be used only in dev, you can place them into the this section (in appKernel.php)

if (in_array($this->getEnvironment(), array('dev', 'test'))) {
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
            $bundles[] = new Sf2gen\Bundle\GeneratorBundle\Sf2genGeneratorBundle();
        }

You also need to make some server tuning by désactivating xdebug and adding eacclerator (or someting else for caching performance)

I also advice to rename app_dev.php to disactivate dev mode

Chopchop
  • 2,899
  • 18
  • 36
0

Basic configuration information can be found here: http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html

One important spot where many people stumble is asset management. When accessing the app via the app.dev front controller (see fist link), it may be necessary to dump the assets first. Read all about it here: http://symfony.com/doc/current/cookbook/assetic/asset_management.html#cookbook-assetic-dumping

0

The Symfony CookBook has now a few recipes about deployment covering:

Taz
  • 3,718
  • 2
  • 37
  • 59
0

Symfony2 How to Master and Create new Environments http://symfony.com/doc/current/cookbook/configuration/environments.html

Dung
  • 19,199
  • 9
  • 59
  • 54