Symfony2 Tutorial Part 1: Project Setup

About this tutorial:

In this tutorial I will show you how to setup a new symfony2 project on a local webserver. I use Linux Mint 17 with the following packages installed:

apache2 apache2-mpm-prefork curl mysql-server php-apc php5 php5-cli php5-intl php5-sqlite php5-xdebug php5-xsl phpmyadmin php5-curl php5-mcrypt

enable php5-mcrypt:

php5enmod mcrypt

Lets get started.

Install symfony2

  1. Install composer:
    I use the following command as root:

    curl -sS | php -- --install-dir=/usr/bin
  2. Create a MySQL database:
    On your MySQL console:

    CREATE DATABASE symfony;
    GRANT ALL ON symfony.* TO symfony@'localhost' IDENTIFIED BY 'pa$$word';
  3. Get symfony2:
    Open a terminal and type

    composer.phar create-project symfony/framework-standard-edition /your/symfony/dir '2.5.*'

    HINT: You can replace '2.5.*' with your preferred symfony2 version. For example use '2.3.*' if you want to use the LTS version.

  4. Configure ACL:
    How to install and configure acl:
    Open a terminal and type in the following commands.

    cd /your/symfony/dir
    HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\  -f1`
    sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
    sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs

Setup your webserver

  1. Create /etc/apache2/sites-available/symfony.conf as root with the following content.
    <VirtualHost *:80>
    	ServerName symfony
            ServerAlias symfony.yourhostname
    	ServerAdmin webmaster@localhost
    	DocumentRoot /your/symfony/dir/web
    	<Directory />
    		DirectoryIndex app.php
    		Options FollowSymLinks
    		AllowOverride All
    		Require all granted
    	<Directory "/your/symfony/dir/web">
    		Options Indexes FollowSymLinks MultiViews
    		AllowOverride All
    		Require all granted
    	ErrorLog ${APACHE_LOG_DIR}/symfony_error.log
    	CustomLog ${APACHE_LOG_DIR}/symfony_access.log combined
  2. run
    sudo a2ensite symfony


    sudo service apache2 reload
  3. edit /etc/hosts and add: symfony.yourhostname symfony

HINT: The apache mod rewrite is not enabled by default. You enable it with:

sudo a2enmod rewrite
sudo service apache2 restart

HINT: you can check if you have configured your server correctly with:

cd /your/symfony/dir
php app/check.php

In most cases the date.timezone parameter in both /etc/php5/apache2/php.ini and /etc/php5/cli/php.ini is not set. In my case it’s: date.timezone = "Europe/Berlin".
You can find a list of different timezones here:

Access your symfony2 application

Thats it. You can now access your symfony2 application (development) via
And the production environment via

At this point you will get an 404 error because you don’t have any content to be shown yet. Don’t worry we will add something in the next part.

One thought on “Symfony2 Tutorial Part 1: Project Setup”

Leave a Reply

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