The definitive guide of Symfony 1.0

3.3. Setting Up an Application

As you learned in Chapter 2, symfony gathers related applications in projects. All the applications of a project share the same databases. In order to set up an application, you must first set up a project.

3.3.1. Creating the Project

Each symfony project follows a predefined directory structure. The symfony command line automates the creation of new projects by initiating the skeleton of the project, with the proper tree structure and access rights. So to create a project, simply create a new directory and ask symfony to make it a project.

For a PEAR installation, issue these commands:

> mkdir ~/myproject
> cd ~/myproject
> symfony init-project myproject

For an SVN installation, create a project with these commands:

> mkdir ~/myproject
> cd ~/myproject
> php /path/to/symfony/data/bin/symfony init-project myproject

The symfony command must always be called from the project's root directory (myproject/ in the preceding examples), because all the tasks performed by this command are project-specific.

Symfony will create a directory structure that looks like this:

apps/
batch/
cache/
config/
data/
doc/
lib/
log/
plugins/
test/
web/

Tip The init-project task adds a symfony script in the project root directory. This PHP script does the same as the symfony command installed by PEAR, so you can call php symfony instead of symfony if you don't have native command-line support (for SVN installations).

3.3.2. Creating the Application

The project is not yet ready to be viewed, because it requires at least one application. To initialize it, use the symfony init-app command and pass the name of the application as an argument:

> symfony init-app myapp

This will create a myapp/ directory in the apps/ folder of the project root, with a default application configuration and a set of directories ready to host the file of your website:

apps/
  myapp/
    config/
    i18n/
    lib/
    modules/
    templates/

Some PHP files corresponding to the front controllers of each default environment are also created in the project web directory:

web/
  index.php
  myapp_dev.php

index.php is the production front controller of the new application. Because you created the first application of the project, symfony created a file called index.php instead of myapp.php (if you now add a new application called mynewapp, the new production front controller will be named mynewapp.php). To run your application in the development environment, call the front controller myapp_dev.php. You'll learn more about these environments in Chapter 5.