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 generate:project myproject
For an SVN installation, create a project with these commands:
> mkdir ~/myproject > cd ~/myproject > php /path/to/symfony/data/bin/symfony generate:project myproject
Symfony will create a directory structure that looks like this:
apps/ cache/ config/ data/ doc/ lib/ log/ plugins/ test/ web/
generate: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 generate:app command and pass the name of the application as an argument:
> php symfony generate:app frontend
This will create a
frontend/ 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/ frontend/ config/ i18n/ lib/ modules/ templates/
Some PHP files corresponding to the front controllers of each default environment are also created in the project
web/ index.php frontend_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
frontend.php (if you now add a new application called
backend, the new production front controller will be named
backend.php). To run your application in the development environment, call the front controller
frontend_dev.php. Note that for security reasons the development controller is available only for localhost by default. You'll learn more about these environments in Chapter 5.
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.