The symfony Cookbook

Installing symfony on IIS

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


About

You are currently reading "The symfony Cookbook" which is licensed under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License license.

Master symfony

Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).
trainings.sensiolabs.com

Books on symfony

Learn more about symfony with the official guides.
books.sensiolabs.com

L'audit Qualité par SensioLabs

200 points de contrôle de votre applicatif web.
audit.sensiolabs.com

Chapter Content

What do we need?

Install symfony

Initialize the project

Configure IIS

Configuration of URL rewriting

Configuring symfony

Configuring a symfony application in its own directory

symfony training
Be trained by symfony experts
Feb 21: Köln (Getting Started with Symfony2 - English)
Feb 27: Köln (Mastering Symfony2 - English)
Mar 05: Köln (Web Development with Symfony2 - Deutsch)
Mar 05: Montreal (Web Development with Symfony2 - English)
Mar 05: Montreal (Getting Started with Symfony2 - English)
and more...

Search


powered by google
You are currently browsing "The symfony Cookbook" in English for the 1.1 version - Switch to version: - Switch to language:
Creative Commons License This work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License.
Translation of this work into another language is explicitly allowed.
This version of symfony is not maintained anymore.
If some of your projects still use this version, consider upgrading as soon as possible.

Yes, there's something else than Apache for web servers. That's why we'll see in this tutorial how to install symfony on IIS.

What do we need?

Install symfony

First, update the pear package, since you need the version 1.4.0 to handle channels:

$ pear upgrade PEAR

Then, add the symfony channel:

$ pear channel-discover pear.symfony-project.com

Install symfony beta version >= 0.5.73:

$ pear install symfony/symfony-beta

if you don't have the phing package, you will need to install it as well:

$ pear install http://phing.info/pear/phing-current.tgz

Find more about symfony installation.

Initialize the project

To create the directory of your project (let's use c:\myproject) and the basic tree structure for an application called myapp, open a command console and type :

$ cd c:\myproject
$ symfony init-project myproject
$ symfony init-app myapp

Configure IIS

We'll consider two configurations options from now on:

Add a virtual directory in the main directory of your server. Name it sf and configure it to data\symfony\web\sf of your pear directory. If you installed php5 in c:\php5 with default configuration, the full path is C:\php5\PEAR\pear\data\symfony\web\sf.

Configuration of URL rewriting

We'll assume that isapi/rewrite is installed and running on your server. We have not yet bought it, so we only have one httpd.ini file to configure. The configuration depends on the options defined previously:

You may restart IIS.

Configuring symfony

The last step is editing the file settings.yml located in the config directory of our symfony project (c:\myproject\apps\myapp\config\ in our example). You won't be surprised to find a little difference between our two options, so:

Important note: if you don't use isapi/rewrite/, the HTTP_X_REWRITE_URL may be wrong. You'll have to make a specific test to know how to configure symfony. Open the file myapp_dev.php (or whatever you named your application_dev.php) in the web directory of your project, and add these following lines on line 2 :

print phpinfo();
die();

Now open the following URL : http://myproject/myapp_dev.php/test/rewrite (or http://myserver/myproject/myapp_dev.php/test/rewrite depending your configuration), and look at the PHP Variables. If _SERVER["PATH_INFO"] equals /test/rewrite, remove the path_info_key line from settings.yml, else you'll have to find the name of the variable containing this value (HTTP_X_REWRITE_URL for isapi/rewrite/). Remove the previous two lines, symfony is ready.

Configuring a symfony application in its own directory

A symfony project may contain several applications. In the default configuration, all the applications share the same css and uploads directory. Let's change this and create a specific directory for our application myapp. Considering our previous options, we'll manage to have these URLs : http://myproject/myapp and http://myserver/myapp. This time, there are no differences in the configuration between these options.

Create a subdirectory myapp in the web directory of your symfony project (to have in our case c:\myproject\web\myapp).

Copy the files index.php and myapp_dev.php in this directory, create there two directories named css and uploads.

In IIS administration console, create a new virtual directory on the root of your server named myapp. Configure this virtual directory to c:\myproject\web\myapp.

Add these lines at the end of your httpd.ini file:

  #[Configuration for direct myapp access]
  # we skip all files with .something except .html
  RewriteCond URL /myapp/.*\..+$
  RewriteCond URL (?!/myapp/.*\.html$).*
  RewriteRule /myapp/(.*) /myapp/$1 [L]

  # we keep the .php files unchanged
  RewriteRule /myapp/(.*\.php)(.*) /myapp/$1$2 [L]

  # finally we redirect to our front web controller
  RewriteRule /myapp/(.*) /myapp/index.php [L]

Edit the file settings.yml of myapp application (c:\myproject\apps\myapp\config\settings.yml) and make sure you have the following lines:

  all:
   .settings:
     path_info_key:          HTTP_X_REWRITE_URL

(see previous note concerning HTTP_X_REWRITE_URL)

Finally, edit both front controllers (index.php and myapp_dev.php in c:\myproject\web\myapp) and change:

define('SF_ROOT_DIR',    realpath(dirname(__FILE__).'/..'));

to:

define('SF_ROOT_DIR',    realpath(dirname(__FILE__).'/../..'));

That's it, you're done.

Questions & Feedback

If you find a typo or an error, please register and open a ticket.

If you need support or have a technical question, please post to the official user mailing-list.