## Index → Cookbook

## Cookbook: Setting up Symfony Framework

The Symfony Framework is a PHP framework focused on building more secure, reliable, and modern Web 2.0 applications.

It is essential that Cherokee supports PHP before starting with this recipe. That should not be a problem since it comes preconfigured by default. However, you can follow the setting up PHP recipe for further hints on fine tuning this feature.

To make sure the recipe works, we'll initialize a simple symfony application.

This assumes that you already have symfony installed and configured. You can find information about installation here: Symfony Installation. At the time of writing, symfony stable version is 1.2.

Now that you have symfony installed, we shall create a symfony application in the folder `~/demo`

Open a terminal, and execute the following commands (note that if symfony is not in your $PATH, you need to prefix symfony with the actual path to the script):

    mkdir ~/demo
    cd ~/demo
    symfony generate:project demo
    symfony generate:app demo
    symfony generate:module demo demo

The above commands will create a symfony project called `demo` inside the demo folder we just created. Next, it will create an application called `demo` as well, and then create a module, also called `demo`.

So now that we have the files in place, we'll just create the needed rules for the web server. Specially important will be the rewrite rules.

Launch cherokee-admin, and proceed to the Virtual servers section. Select or create the virtual server that you will be configuring and go to the `Behavior` tab to set up the rules. Remember that the document root for this virtual server should be the `web` folder in your demo project.

Steps

1. You will need to keep the rule for the `php` extension. If this rule is not present, create it as described in setting up PHP.

2. Next, configure a rule with the handler `File Exists` that should be set to a priority lower than that of the `php` rule. This one can be set to match whatever files you like, but the important thing is to check the `Match any file` checkbox. Let this rule be handled by the Static Content handler.

3. Afterwards, modify your `Default` rule by configuring the redirection handler, through the `Handler` tab.

   Type | Regular Expression | Substitution
   --- | --- | ---
   Internal | ^.*$ | /index.php

4. Symfony includes two controllers. One of them is "index.php". The redirection above only makes the "index.php" controller accessible. If you are actively developing the web application, you may wish to have access to the symfony debug toolbar. In this case, replace "/index.php" substitution with "appname_dev.php" where `appname` is the name of the symfony application you are setting up. In this example, our application name is "demo" so this controller will be called "demo_dev.php".

5. Finally, you need to set up a rule for the "/sf" directory.

   Type | Web Directory | Handler | Document Root
   --- | --- | --- | ---
   Directory | /sf | Static content | /usr/share/php/data/symfony/web/sf

Note that the document root for the /sf directory depends on your installation. The value given above corresponds to a pear installation of symfony on an Ubuntu 8.10 (Intrepid Ibex) system.

You may need to edit your "hosts" file to include the domain name you call the virtual server. Your symfony application should then be accessible. You can find more information about setting up symfony applications in the symfony manual.

Figure: Running application