Configuring IIS7 without the GUI

If you're like me, you're pretty used to using a text editor to set up your webserver and find gui's quite frankly annoying (and you can't store them in $insert_your_vcs_of_choice)

But IIS7 actually holds all it's configuration in plain XML files, which are really quite easy to edit by hand. It's just a question of WHERE these files end up.

I'm not going to go into the details of all the options and xml necessary, but here are a few tips.

By default a web.config file is placed in the webroot of whatever site you've set up - this should be used for site local configuration

For me this means defaultDirectory information (index.php is my friend) and rewrite rules (if you're not using URL Rewrite you're insane)

Your "overall" web server configuration is hidden really well. It's in your windows directory - usually c:\\Windows but your location may vary

so head to C:\\Windows\\System32\\inetsrv\\config and you'll find those nice hidden config files. Now, technically you won't be allowed to edit those files, but as long as you have Admin privileges on the windows machine, here's the dirty trick. Drag the file out of the directory onto your desktop. Edit and save, drag it back in place.

The file you're probably interested in is applicationHost.config The reason I initially went hunting for it was to set a PHPRC environment variable, so silly PHP gets the right .ini file. But because I have many PHP versions installed I did NOT want to have that set as a system wide variable. I also could set up an APPLICATION_INI variable for Zend Framework, which happened to be running on that version of PHP. AND I could set two versions of PHP to run, and tell the site configuration which one to use.

<pre>
<fastCgi>
    <application fullpath="C:\\Program Files (x86)\\php-5.3.1-nts\\php-cgi.exe" arguments="" monitorchangesto="" stderrmode="ReturnStdErrIn500" maxinstances="4" idletimeout="300" activitytimeout="30" requesttimeout="90" instancemaxrequests="200" protocol="NamedPipe" queuelength="1000" flushnamedpipe="false" rapidfailsperminute="10">
    </application>
    <application fullpath="C:\\Program Files (x86)\\php-5.2.12-nts\\php-cgi.exe" arguments="" monitorchangesto="" stderrmode="ReturnStdErrIn500" maxinstances="4" idletimeout="300" activitytimeout="30" requesttimeout="90" instancemaxrequests="200" protocol="NamedPipe" queuelength="1000" flushnamedpipe="false" rapidfailsperminute="10">
    <environmentVariables>
        <environmentVariable name="PHPRC" value="C:\\htdocs\\config">
        <environmentVariable name="APPLICATION_INI" value="C:\\htdocs\\config\\local_app.ini">
    </environmentVariables>
    </application>
</fastCgi>
</pre>

Now that I know where the files hide, and have taken some time to figure out all the xml available (I spent some time reading the reference, just as I had to learn apache's configuration information) I can store my configurations and set up new servers quickly and easily.

Notice, just like apache httpd.conf changes, you'll have to restart your webserver if you change the xml ;)

Comments

Aschwin Wesselius

Thanks! I wouldn't go after changes in IIS myself, but this is one of enormous proportions (for me). I moved away from IIS (and Windows Server in general) just because of the fact the configuration wasn't editable nor it was trackable. So now the power comes to IIS finally...

2010-02-24 12:50 am

chat

thanks wery nice write

2010-05-13 5:51 pm

Kanwaljeet Singla

IIS FastCGI module is supposed to detect changes to applicationHost.config and restart FastCGI process pools when a change is made. Let me know if you were required to restart your webserver after making above changes.

Thanks,
Kanwal

2010-05-23 5:05 pm

Post a Reply