Install PHP/Symfony2 under IIS
Web agency » Digital news » Install PHP/Symfony2 under IIS

Install PHP/Symfony2 under IIS

Today, I propose you a method allowing to execute PHP on the IIS platform. In my case I used IIS 7.5 and PHP 5.4.

Install IIS

This is how to install the platform. This is done simply via "Add Features" in Windows.

You will find this feature in "Control Panel", "Programs and Features" and in the left panel "Turn Windows features on or off". At this time, check “IIS Internet Services”.

WARNINGS, you will need to open the port used (by default 80 in TCP connection) to access it from the outside. The procedure to follow is on the Microsoft site.

Install PHP

How to install PHP simply? I give you the method.

Download PHP 5.4 No Thread Safe (in my case, it was not possible for me to plug in a version prior to PHP 5.4 for technical reasons, but you are free to do so).

  • Unzip the archive and install the contents in an appropriate folder. I put it in the root (C: PHP). You are free to choose another location.
  • In your PHP folder, create the file php.ini by copying php.ini-production.
  • Edit the php.ini file
    Uncomment line " extension_dir="ext" »
    Enable the open_ssl, file_info, php_mbstring.dll extensions by uncommenting the lines
    Add the " Europe / Paris " at " date.timezone »

Link IIS and PHP

We are going to map IIS to PHP so that files of type *.php are sent to php.exe.

  • In IIS Manager, select your server on the left side and then click on “Manager Mappings”.
  • In the right panel, "Add a module mapping".
    Request path: * .php
    Module: FastCgiModule
    Executable: Select php-cgi.exe
    Name: PHP

Link an IIS and Symfony2

IIS is a little different from Apache, that's why I put you the procedure to easily plug a Symfony2 project.

  • In IIS Manager, " Add a website (right click on the server used).
  • Fill out the form
    Physical path: you must not choose the root of your project but the folder website because only the runtime folder is of interest to IIS.
  • Now you need to add the default file. In IIS Manager, choose "Default document" and click "Add". In our case, we add app.php but you could very well add others.
  • For many reasons, you need to set up URL rewriting.
    Here is the link that will allow you to simply add "URL Rewrite"
  • Once the extension is installed, you need to configure rewriting.
    Edit file web.config located in your "web" folder. This is where all your configuration is written.
    In this file, between the tags, copy this rule:
<rule name="Rewriter" stopProcessing=“true”>
<match url=“^(.*)$” ignoreCase=“false” />
<add input="{R:1}" pattern=“^(app.php|favicon.ico)” ignoreCase=“false” deny=“true” />
<add input="{REQUEST_FILENAME}" matchType=“IsFile” ignoreCase=“false” deny=“true” />
<add input="{REQUEST_FILENAME}" matchType=“IsDirectory” ignoreCase=“false” deny=“true” />
<action type=“Rewrite” url=“./app.php/{R:1}” appendQueryString=“true” />

And there you have it, I hope this long note has been useful to you.

★ ★ ★ ★ ★