Symfony 2 production environment server deploy

Symfony 2 logo

Symfony 2 logo

Symfony 2 is one of the most popular PHP frameworks and particularly my favorite. My fist time to deploy a project in production environment, I have struggled a lot. One of the most common errors you might get when you execute the prod environment is “401 Page Not found”. But, actually it is really simple to make a Sysfony 2 project work. you just have play a little bit around with it knowing what you want.

Note: This post is about how to move a bundle to production environment, if what you want to know is how to install Symfony (by meeting it’s requirements), you can go here. Also to instal Symfony in windows 8 PC with wamp server you can go here.

Note: Last update on 2014-04-09.

1. On a linux alike system Log to the project folder using the cd command

2. execute this 3 commands:

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

3. Promote the web server's user the owner of the cache folder, as root you should execute in Linux systems

chown www-data:www-data -R app/cache

4. Promote the web server’s user the owner of the logs folder, as root you should execute in Linux systems.

 chown www-data:www-data -R app/logs

In my case it was like this:

[email protected]:/var/www/Org# php app/console assets:install web
Installing assets using the hard copy option
Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
Installing assets for Acme\DemoBundle into web/bundles/acmedemo
Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution
[email protected]:/var/www/Org# php app/console assets:install web
Installing assets using the hard copy option
Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
Installing assets for Acme\DemoBundle into web/bundles/acmedemo
Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution
[email protected]:/var/www/Org# php app/console assetic:dump web
Dumping all dev assets.
Debug mode is on.

[email protected]:/var/www/Org# chown www-data:www-data -R app/cache
[email protected]:/var/www/Org# chown www-data:www-data -R app/logs
[email protected]:/var/www/Org# php app/console cache:clear --env=prod --no-debug
Clearing the cache for the prod environment with debug false
PHP Parse error:  syntax error, unexpected '$content' (T_VARIABLE) in /var/www/Org/src/Osd/RetireBundle/Controller/GeneralController.php on line 15
[email protected]:/var/www/Org# php app/console cache:clear --env=prod --no-debug
Clearing the cache for the prod environment with debug false
[email protected]:/var/www/Org# php app/console assets:install web
Installing assets using the hard copy option
Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
Installing assets for Acme\DemoBundle into web/bundles/acmedemo
Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution
[email protected]:/var/www/Org# php app/console assetic:dump web
Dumping all dev assets.
Debug mode is on.

[email protected]:/var/www/Org# chown www-data:www-data -R app/logs
[email protected]:/var/www/Org# chown www-data:www-data -R app/cache
[email protected]:/var/www/Org#

 

Note: This update was done because of the question from César Chalén.

If you need also apache to take you directly to the default project page you just need to create a Virtual host pointing to Symfony 2’s internal web directory (if you need more detailed info about the apache virtual hosts you can see it here). Any way check out one of my virtual hosts:

<virtualhost *:80>
        ServerAdmin [email protected]
        ServerName retirement.gabs.hospitals.moh.gov.bw
        DocumentRoot /var/www/Symfony/web

        <directory /var/www/Symfomy/www/web></directory>

                Options Indexes FollowSymLinks MultiViews
                AllowOverride all
                Order allow,deny
                allow from all

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined

</virtualhost>

And that is it, enjoy.

4 comments on “Symfony 2 production environment server deploy
  1. abel says:

    Hello:
    Check the logs from Symfony, and post what they are saying. Probably the logs will give you some clue. Once I had the same problem and even the logs were not saying any thing. then I checked the logs from Apache and there was an issue there.
    Regards

  2. César Chalén says:

    It works! Now my dev env is updated, but i’m still entering /app.php/index to access env prod mode.

  3. Adeniyi says:

    Symfony 2 production environment server deploy where my server is a WAMP server. Please how do I achieve this.

1 Pings/Trackbacks for "Symfony 2 production environment server deploy"
  1. […] I have a small application made in symfony 2.3.5 and it is working on my local computer dev and prod environments, and also on the deployment server runs ok from the localhost the development environment, but not the production env, so i dont think is a requirements issue. I have clear the cache and made the www-data user the owner of the log and chache directories following this guide. […]

Leave a Reply

Your email address will not be published. Required fields are marked *

*