Symfony2 Tutorial Part 1: Project Setup

This Post is deprecated! See Symfony 2.1.0 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 Ubuntu 10.04 with the following packages installed:

acl apache2 apache2-mpm-prefork git-core mysql-server-5.1 php-apc php5 php5-cli php5-intl php5-sqlite php5-xdebug php5-xsl phpmyadmin

Lets get started.

  1.  Download Symfony Standard 2.0.7 (http://symfony.com/download?v=Symfony_Standard_Vendors_2.0.7.tgz).
  2. Extract.
  3. Git setup:
    1. In your project directory run:
      git init
      git add *
      git commit -m 'initial import'

      Hint: If you want to ignore a directory simply create a .gitignore file in which you can specify which files or folders are to be ignored. You can put a .gitignore file in any directory you like

  4. Setup your webserver:
    1. Create /etc/apache2/sites-available/symfonywith the following content:
      <VirtualHost *:80>
      	ServerName symfony.yourhostname
      	DocumentRoot /path/to/your/Symfony/web
      	DirectoryIndex index.php
      	<Directory /path/to/your/Symfony/web>
      		AllowOverride All
      		Allow from All
      	</Directory>
      </VirtualHost>
    2. Run
      sudo a2ensite symfony
    3. Add
      127.0.0.1 symfony.yourhostname

      to /etc/hosts

    4. Run
      sudo /etc/init.d/apache2 reload

    You should check if your server configuration is correct. You can do that with the symfony2 config script: http://symfony.yourhostname/config.php

    Now you can access your Symfony2 project via http://symfony.yourhostname and http://symfony.yourhostname/app_dev.php
    Hint: you need to enable modrewrite to be able to use http://symfony.yourhostname instead of http://symfony.yourhostname/app.php to enable it simply run:

    sudo a2enmod rewrite
    sudo /etc/init.d/apache2 restart
  5. Setup ACL’s:
    sudo setfacl -R -m u:www-data:rwx -m u:yourusername:rwx app/logs/ app/cache/
    sudo setfacl -dR -m u:www-data:rwx -m u:yourusername:rwx app/logs/ app/cache/

    you do this, because your webserver (www-data) and yourself need access to the cache and logs directories. Here you can read how to setup and enable acl’s.
    Hint: When you get an empty white page in the production environment, its very often the case that your webserver has no write access in the cache and or logs directories.

  6. Setup your Database:
    On your MySQL console run:

    CREATE DATABASE symfony;
    GRANT ALL ON symfony.* TO symfony@'localhost' IDENTIFIED BY 'pa$$word';
  7. Setup your symfony config:
    replace the content of app/config/parameters.ini with the following:

    ; These parameters can be imported into other config files
    ; by enclosing the key with % (like %database_user%)
    ; Comments start with ';', as in php.ini
    [parameters]
        database_driver   = pdo_mysql
        database_host     = localhost
        database_port     =
        database_name     = symfony
        database_user     = symfony
        database_password = pa$$word
    
        mailer_transport  = smtp
        mailer_host       = localhost
        mailer_user       =
        mailer_password   =
    
        locale            = en
    
        secret            = Dah0cie3kaeS8Eipoo9ahxei8voe1IeR

And that’s it. Now you can use your nice new Symfony2 installation.

If you want to know more about the symfony2 project setup, read the official documentation: http://symfony.com/doc/2.0/book/installation.html

Tags: , , , , , , ,

Leave a Reply

You must be logged in to post a comment.