![]() |
|
The symfony CookbookInstalling symfony on IIS |
|
You are currently reading "The symfony Cookbook" which is licensed under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 Unported License 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. |
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.
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
phingpackage, you will need to install it as well:$ pear install http://phing.info/pear/phing-current.tgz
Find more about symfony installation.
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
We'll consider two configurations options from now on:
http://myproject/. Assuming the directory in which you created the directory myapp is c:\myproject\, configure the root directory of your server to be c:\myproject\web (in IIS administration console).http://myserver/myproject/. In IIS administration console, create a new virtual directory on the root of your website for the directory c:\myproject\web.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.
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:
for URLs like http://myproject/ we need:
# Defend your computer from some worm attacks RewriteRule .*(?:global.asa|default\.ida|root\.exe|\.\.).* . [F,I,O] # we skip all files with .something except .html RewriteCond URL .*\..+$ RewriteCond URL (?!.*\.html$).* RewriteRule (.*) $1 [L] # we keep the .php files unchanged RewriteRule (.*\.php)(.*) $1$2 [L] # finally we redirect to our front web controller RewriteRule (.*) /index.php [L]
for URLs like http://myserver/myproject/ we need:
# Defend your computer from some worm attacks RewriteRule .*(?:global.asa|default\.ida|root\.exe|\.\.).* . [F,I,O] # we skip all files with .something except .html RewriteCond URL /myproject/.*\..+$ RewriteCond URL (?!/myproject/.*\.html$).* RewriteRule /myproject/(.*) /myproject/$1 [L] # we keep the .php files unchanged RewriteRule /myproject/(.*\.php)(.*) /myproject/$1$2 [L] # finally we redirect to our front web controller RewriteRule /myproject/(.*) /myproject/index.php [L]
You may restart IIS.
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:
for URLs like http://myproject/, we need these lines:
all:
.settings:
path_info_key: HTTP_X_REWRITE_URL
for URLs like http://myserver/myproject, we need these lines:
all:
.settings:
path_info_key: HTTP_X_REWRITE_URL
Important note: if you don't use isapi/rewrite/, the
HTTP_X_REWRITE_URLmay be wrong. You'll have to make a specific test to know how to configure symfony. Open the filemyapp_dev.php(orwhatever 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(orhttp://myserver/myproject/myapp_dev.php/test/rewritedepending your configuration), and look at the PHP Variables. If_SERVER["PATH_INFO"]equals /test/rewrite, remove thepath_info_keyline fromsettings.yml, else you'll have to find the name of the variable containing this value (HTTP_X_REWRITE_URLforisapi/rewrite/). Remove the previous two lines, symfony is ready.
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.
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.