Symfony2 Jobeet Day 1: Starting up the Project

Today we will setup the development environment, install Symfony2 and display a page of the application in a web browser. First of all, you need to check that your computer has a friendly working environment for web development. At a minimum, you need a web server (Apache, for instance), a database engine (MySQL), and PHP 5.3.2 or later.

Download and install Symfony2

Prepare a directory on your web server where you want to install the new project. We will name this directory jobeet as the name of our future website. Then go to, choose “Symfony Standard” (the version with vendors) and download it (at the moment of writing this tutorial, the latest Symfony version was 2.0.11). After downloading, unpack the archive and copy the contents of “Symfony” dir to your project directory. You should now have something like this:

Web Server Configuration

A good web practice is to put under the web root directory only the files that need to be accessed by a web browser, like stylesheets, JavaScripts and images. By default, it’s recommended to store these files under the web/ sub-directory of a symfony project.

To configure Apache for your new project, locate and open the httpd.conf configuration file and add the following configuration at the end:

<VirtualHost *:80>
    ServerName jobeet.local
    DocumentRoot /home/dragos/work/jobeet/web
    DirectoryIndex app.php
    ErrorLog /var/log/apache2/jobeet-error.log
    CustomLog /var/log/apache2/jobeet-access.log combined
    <Directory "/home/dragos/work/jobeet/web">
        AllowOverride All
        Allow from All

Change the above configuration to reflect your setup and then restart your web server.

This is the standard way to define a new virtual host in Apache. Depending on your server configuration or Apache version, some things might be slightly different. For example in Ubuntu you have to create a new file in the folder /etc/apache2/sites-enabled/ named jobeet with the above content.

The domain name jobeet.local used in the Apache configuration has to be declared locally. If you run a Linux system, it has to be done in the /etc/hosts file. If you run Windows, this file is located in the C:\WINDOWS\system32\drivers\etc\ directory. Add in the following line: jobeet.local

Test the Symfony2 Installation

After restarting Apache, open a browser window and type in http://jobeet.local/app_dev.php. You should see the following page:

To avoid some headaches further down the line, check that your configuration can run a Symfony2 project smoothly by requesting the following URL: http://jobeet.local/config.php. Make sure you don’t have any Major Problems listed, and follow the optional recommendations listed (if any).

Symfony2 console

Just like Symfony 1.x, Symfony2 comes with the console component tool that you will use for different tasks. To see a list of things it can do for you type at the command prompt:

 php app/console list

Creating the Application Bundle

As you know, a Symfony2 project is made up of bundles. Even the Symfony framework is a bundle. To create a new bundle for our application run from the command line:

php app/console generate:bundle --namespace=Ens/JobeetBundle --format=yml

The generator will ask you some questions before generating the bundle. Here are the questions and the answers (all except one are the default answers):

Bundle namespace [Ens/JobeetBundle]: Ens/JobeetBundle
Bundle name [EnsJobeetBundle]: EnsJobeetBundle
Target directory [/home/dragos/work/jobeet/src]: /home/dragos/work/jobeet/src
Configuration format (yml, xml, php, or annotation) [yml]: yml
Do you want to generate the whole directory structure [no]? yes
Do you confirm generation [yes]? yes
Confirm automatic update of your Kernel [yes]? yes
Confirm automatic update of the Routing [yes]? yes

Clear the cache after generating the new bundle with:

 php app/console cache:clear --env=prod
 php app/console cache:clear --env=dev

The new Jobeet bundle can be now found in the src directory of out project: src/Ens/JobeetBundle. The bundle generator made a DefaultController with an index action. You can access this in your browser: http://jobeet.local/hello/jobeet or http://jobeet.local/app_dev.php/hello/jobeet

The Environments

As Symfony 1.x, Symfony2 also has different environments. If you look in the project’s web directory, you will see two php files: app.php and app_dev.php. These files are called front controllers; all requests to the application are made through them. The app.php file is for production environment and app_dev.php is used by web developers when they work on the application in the development environment. The development environment will prove very handy because it will show you all the errors and warnings and the Web Debug Toolbarthe developer’s best friend.

That’s all for today. See you on the next day of this tutorial when we will talk about what exactly the Jobeet website will be about!

Symfony2 Jobeet Day 2: The Project

16 thoughts on “Symfony2 Jobeet Day 1: Starting up the Project”

    1. You have to run this inside your project folder. If it still does not work check if the app/console file exists. Also be sure you downloaded the Symfony 2.0 version, not the 2.1 RC version.

        1. Check your app/config/routing.yml for correct route rules.

          app_dev.php use routing_dev.yml
          app.php use routing.yml

          Also you may use bundle-specific routing.yml

  1. i installed lamp server on ubuntu 12.10 but i coudn’t find httpf.conf fille? how to resolve virtual host? maybe it’s etc/hosts right?

  2. I’m getting the following error when I go to confirm generation:

    Warning: mkdir(): Operation not supported in /Library/WebServer/symfony/ven
    or.php line 36

    Any idea how I fix this one?

  3. @Josiah

    Try to remove yout vendor library from “/Library/WebServer/symfony/” and then type in console composer.phar install. This should settle the matter.

  4. Hi,

    A Good Tutorial to step-in. I followed the same steps as mentioned by you. I installed the latest Symfony2 version. But, i am facing the following error when running http://my.local/app_dev.php :

    No route found for “GET /”
    404 Not Found – NotFoundHttpException
    1 linked Exception: ResourceNotFoundException »

    May i know why this happens.

Leave a Reply

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