Saturday, August 30, 2008

Application Pools in IIS 6

Hi, I recently came across this question on the IIS community newsgroup. This would be a great question to share, as the answer incorporated has fundamental points regarding IIS 6 Application Pool that will really help a beginner to start off:

Question.) I will soon install a small Ajax Asp.Net "single page" site on a client site. This page is simply polling a Asp.Net Web service, which fetches and returns parameters (temperature, air conditioning status...) to be displayed on the page. This is implemented with an Ajax Timer control server.

1.) Now this is my first "industrial" web site, and I'm concerned about its robustness. Do I need to create a specific pool on IIS 6 for the web service and the site ?
2.) I'm aware than it is possible to "recycle" a pool. Do I need this ?

Just to give you a background, the user is using Windows Server 2003 Standard Edition running IIS 6 and has all the required dependencies installed properly (ASP, .Net). Next, lets grab some base level knowledge on Application Pools before we hit on the answers.

To begin with, an Application Pool is a concept that was introduced in IIS 6. The major reason for this was Application Isolation and in a short while you will understand how.

The 2 modes that IIS operates in are the IIS 5 Isolation mode, where in, IIS 6 acts similar to IIS 5 architecture. Therefore, you cannot make use of AppPools or it's concept in this mode. Whereas , when you run IIS 6 in the Worker Process Isolation Mode (WPIM) you can combine/separate web applications or web sites into groups called Application Pools. Application Pools are nothing but the URL collection of the web application or web site that will now run under one or several worker process (W3WP.exe).

A quick point: While an Application Pool is serving a request, the same request cannot be routed to another Application Pool. However, subsequent request can go to a new AppPool (if defined).
Every application within an application pool shares the same worker process. Therefore, applications that run in 2 different AppPools cannot share or effect each other.

What is the use?? OK...Here comes our

Answer 1.) IIS 6 provides very effective method of process isolation by separating web applications based on w3wp.exe (worker process executable). Hence, an AppPool that may have a dirty code will not effect the website in an adverse manner. Your application pool running a good code will still be up and running as ever.
If you are an IIS admin or a developer who has fair bit of knowledge on IIS will surely understand how important this development is.

Having understood that. let us know try and figure out how the request processing is happening. Now, we all know that the request initially comes to the IIS kernel mode driver HTTP.sys. Further, within HTTP.sys an application pool is represented by a request queue, from which the user-mode worker processes that service an application pool collect the requests.

Knowing this we can move on to our next concept called, Application Pool Recycle. Every now and then when your application goes bad or the application pool crosses a defined set of parameters for an Application Pool property, the w3wp.exe concerning the AppPool will be shutdown (Killed) and a new w3wp.exe will automatically be created in it's. This provides you to have your Application Pool in good health, always. For the sake, of the blog's length I will not go into those parameters and properties but if you wanna know then drop in a comment and I will get back to you. Application Recycling is very important but then it depends on what parameters
and properties of an AppPool you would like to have it recycled. Done with Answer 2 :)

I think I might come up with a few blogs in near future on IIS. Stay Tuned!! :D

Thursday, August 28, 2008

Troubleshooting: Exception Error Codes - What's the Mystery!

Very often as sysadmins we come across numbers that make no sense. Give the same to a debugger and he\she will make your life simpler and happier.
Well I am a no different sysadmin! (well atleast that is what I would like to call myself)
However, off late my association with with these numbers has increased because I have started to understand what some of them mean.

Hmmm... I feel like Neo and the world in front of me is turning into a Matrix of green numbers which made no sense to me the first time I watched the flick! To be honest doesn't make much sense even now.
But I am not talking about numbers like those. What I am talking about are Exception Error Codes. If you take a look at your application logs and have a some exposure to debugging you will be familiar with a series of code that resembles something like C0000008D ... C0000008E ..... 80000002...
Well don't be surprised when you see them and go like "What the hell!!!" because they all mean something and it is their way of telling you what the hell is going wrong

So I thought I should share some of the codes and their meaning that I have collected over the course of few weeks. I know that this list is incomplete and much needs to be done but this is what I have and hope you and I can figure it out someday!

80000002 -> Datatype Misalignment

80000003 -> Breakpoint Exception

C0000005 -> Access Violation (One of the most common)

C0000006 -> In page error

C0000017 -> Not enough quota

C0000010 -> Illegal Instruction

C000008C -> Array Bounds Exceeded

C000008D -> Floating Point Denormal Operand

C000008E -> Floating Point Division by Zero

C000008F -> Floating Point Inexact Result

C0000090 -> Floating Point Invalid Operation

C0000091 -> Floating Point Overflow

C0000092 -> Floating Point Stack Check

C0000093 -> Floating Point Underflow

C0000094 -> Integer Division By Zero

C0000095 -> Integer Overflow

C0000096 -> Privileged instruction

C00000FD -> Stack Overflow

C0000135 -> Unable to locate DLL

C0000138 -> Ordinal Not Found

Will try and update the list as and when I get to know more ...

Friday, August 22, 2008

How To: Using IIS 6.0 Command Line Utilities - Part 2

Continuing my last post on using Command line utilities with IIS 6.0 I will now be discussing on how to use some of those command which can make our life as an IIS admin happy!

Lets start with adsutil.vbs

Working with adsutil.vbs is fairly simple once you get to know how is accepts commands. To know the procedure you must understand the flow of Metabase.xml

Let's start with this easy and short command...

>cscript.exe %systemdrive%\inetpub\adminscripts\adsutil.vbs enum w3svc /P
You will get a reply similar to this:

[/w3svc/1]
[/w3svc/AppPools]
[/w3svc/Filters]
[/w3svc/Info]

We have just enumerated the paths for w3svc by using the /P switch. In my case you see /w3svc/1 as I am running with just the default website. But you would see similar entries of /w3svc/Website_identifier format, if one had more websites. If you want to enum the complete data as well just remove the /P and run the same command.You will loads more data
Even better:
>cscript.exe %systemdrive%\inetpub\adminscripts\adsutil.vbs enum_all w3svc
Huge information right! That just enumerated the entire w3svc for us. Run this command to get the output page by page wise so that we can actually read it this time ;)
>cscript.exe %systemdrive%\inetpub\adminscripts\adsutil.vbs enum_all w3svc | more
Press space bar to view the next page. Anyways this was just something to get us warmed up!
Now lets get something that we might need. I am going to be taking scenario wise.

Scenario 1:
You need to ENUMERATE a few basic settings of your Default Web Site. Here's how you do it:
>cscript.exe %systemdrive%\inetpub\adminscripts\adsutil.vbs enum w3svc/1/
This is will give you a very basic overview of your website. Technically, the previous command will enum all the parameters within the location w3svc/1/ for the Key type IISWebServer with Website Identifier 1 from the In-Memory Metabase.xml. So if you would want to have a look at another site just replace the ID of that site.

Scenario 2:
You need to GET a particular property of your website. Let us consider we need to know the physical path of a directory named test under Default Web Site. Here's how you do it:
>cscript.exe %systemdrive%\inetpub\adminscripts\adsutil.vbs get w3svc/1/test/path
The only thing to get here is that you would need to mention the directory name(test), followed by the object(path) you wish to find.

Scenario 3:
You need to SET new bindings on your Default Web Site. Here is how you do that:
>cscript.exe %systemdrive%\inetpub\adminscripts\adsutil.vbs set w3svc/1/ServerBindings ":81:"
This will set your Website Server Bindings to port 81. Simple enough right!
To save all of the burden of reading long articles let me end adsutil.vbs here. To be honest this was pretty introductory stuff with adsutil.vbs

iisweb.vbs

This is a very useful utility if you want to create, delete or operate upon the status parameters of an IIS website. iisweb comes in very handy when you want to view basic settings and status of a website running within your network. Run this command
>iisweb /query "Default Web Site"
The above command will tell you the current status, bindings with the name of the web site. You can also put together varioius website running on the same server to get a cumulative information. iisweb commands can run on your remote IIS machines.


iisvdir.vbs

A useful utility to create delete and query virtual web directory on IIS 6 machine. To learn more about the difference about a virtual directory and appplication within IIS check my previous post. You can operate iisvdir command on remote IIS machines as well.
>iisvdir /s Server1 /u "username" /p "password" /create "New Vdirectory" Mydir "Physical Path"
Here is a sample script that is going to create a website for us: Copy paste the following and name it as site.bat.
Run site /? for help. Enjoy!

@IF ?%_ECHO%?==?? ECHO OFF
rem This script will create, start, and give us the status using IIS commmand line utilities
rem Written by MA Khan, http://www.iisworkstation.com
SETLOCAL
SET WEBNAME=%1
SET IP=%2
SET PORT=%3
SET SITE_PATH=%4
SET WEB_CREATE=iisweb

rem Provide Help!

IF /I ?"%WEBNAME%"? EQU ?"HELP"? GOTO :Help
SET NEED_HELP=%WEBNAME:?=%
IF /I ?"%NEED_HELP%"? NEQ ?"%WEBNAME%"? GOTO :Help

rem start execution

:menu
ECHO.
ECHO.
ECHO Website creation script by MA Khan
ECHO Version 1.0 BETA 1
ECHO.
ECHO -------------------------------------------------------------------------------
ECHO --^>This script is going to create, start and give us details on the website that we create.
ECHO --^>Website is going to be created by using %WEB_CREATE%
ECHO -------------------------------------------------------------------------------
ECHO.
ECHO.
rem Start the actual work
rem input validation
ECHO Starting input validation...
IF /I ?%IP%? EQU ?? ( ECHO.&ECHO Validation Failed!&Echo.&Echo Check help for the syntax&GOTO :Help)
IF /I ?%PORT%? EQU ?? ( ECHO.&ECHO Validation Failed!&Echo.&Echo Check help for the syntax&GOTO :Help)
IF /I ?%SITE_PATH%? EQU ?? ( ECHO.&ECHO Validation Failed!&Echo.&Echo Check help for the syntax&GOTO :Help)
IF NOT EXIST "%SITE_PATH%" (
ECHO.
ECHO ERROR: Site physical path is not found!
ECHO Please Specify the right address
GOTO :EOF
)

ECHO Validation Succeeded...
ECHO.
ECHO Details given:
ECHO Website Name: %WEBNAME%
ECHO IP: %IP%
ECHO PORT: %PORT%
ECHO SIte Physical Path: %SITE_PATH%
ECHO.
SET CONFIRM=
SET /P CONFIRM=Type EDIT to edit choices or hit ENTER to proceed:
IF ?%CONFIRM%? EQU ?? GOTO :Create

ECHO.
ECHO Press ENTER to accept [%WEBNAME%], or provide new value (Web Site Name)
SET /P WEBNAME=Web Site Name:
ECHO Press ENTER to accept [%IP%], or provide new value (IPV4 Addres only)
SET /P IP=IP V4 only:
ECHO Press ENTER to accept [%PORT%], or provide new value (Port Number)
SET /P PORT=Port Number:
ECHO Press ENTER to accept [%SITE_PATH%], or provide new value (Physical Path of your website)
SET /P SITE_PATH=Physical Path:

ECHO ---------------------------------------------------------------------------
ECHO Restarting with fresh Values
ECHO ---------------------------------------------------------------------------

GOTO :Menu
GOTO :EOF


:Create
ECHO Starting the website creation...
ECHO.
iisweb /create %SITE_PATH% "%WEBNAME%" /i %IP% /b %PORT%
ECHO.
iisweb /query %WEBNAME%
ECHO.
ECHO We are good to go
GOTO :EOF

:Help
ECHO.
ECHO HELP:
ECHO.
ECHO Syntax:
ECHO site [websitename][ipaddress][port][physical path]
ECHO.
ECHO Description:
ECHO This script is going to create, start and give us basic details on the website that we create.Website is going to be created by using %WEB_CREATE%.
ENDLOCAL
GOTO :EOF

Thursday, August 21, 2008

How To: Using IIS 6.0 Command Line Utilities - Part 1

Q.) I would like to control a few operations of my IIS management through batch files. What I am looking at are simple tasks such as Restart IIS on development servers, viewing configuration and stuff like that. How can I possibly achieve that?

I am pretty new at IIS, so please excuse me if this is a simple question.

Ans.) I will be giving you a know how of various command line utilities that you can use if you are running Windows Server 2003 with IIS 6.0. But, from there on it depends on how you make use of this utilities to achieve what is actually needed in your environment.

Let us first start with knowing the different utilities that come by default:

adsutil.vbs - This is the most important command line utility available at your disposal. It lets you work with the entire MetaBase properties. adsutil is located at %systemdrive%/inetpub/AdminScripts/adsutil.vbs by default

Something that I recently learned: Changes made using adsutil.vbs are immediately reflected as these changes are made to the in-memory Metabase and written to the MetaBase.xml file in 2 minutes.
iisreset - This tool gives you all sort of information on Internet services running on your machine along with the ability to start, stop, restart, and reboot of the machine. This is something that I use quite often.

iisapp.vbs
- This utility comes in very handy while troubleshooting an issue. iisapp.vbs gives you the information about the w3wp.exe, it's associated PID(Process ID) and the Application Pool it corresponds to. This utility is located at %windir%\system32\iisapp.vbs

iisvdir.vbs - Lets you create, delete or query a web directory, picked the previous line directly from the help file ;). This is something that I like to user very often as it even works to find quick data from remoteIIS machines. Located at %windir%\system32\iisvdir.vbs

iisweb.vbs - You can create, delete, start, stop or pause a website using iisweb. Really helps if you want to create a website programmatic. Located at %windir%\system32\iisweb.vbs

iisback.vbs - This script lets you backup/restore your IIS settings. Actually it can do a little bit more than that :) it can also list and delete your IIS backups. But these 2 really don't matter much to any of us. iisback.vbs is also located at %windir%\system32\iisback.vbs

iisCnfg.vbs - This script can import, export and copy IIS configurations from one machine to another. To be honest, I haven't really used this one a lot and haven't seen this used in production a lot either. Located at %windir%\system32\IIsCnfg.vbs

iisext.vbs - This is a cool script to have while you are on your development machines. I like the kind of data if outputs. Basically, iisext enables you to play around with your web service extensions. Again, located at %windir%\system32\iisext.vbs

The 2 other scripts related to IIS (FTP) are: IIsFtp.vbs and IIsFtpdr.vbs also located at %windir%\system32\

So as you can see IIS doesn't ship just with cool feature set it also brings along with it great tools and scripts to make our work easier.

If you are a beginner the 1st thing I recommend is to find out how to use HELP. Simple, here is how you would get that info

ADSUTIL.VBS -
From the command prompt run
cscript.exe %systemdrive%\InetPub\AdminScripts\adsutil.vbs help
For all others:
From the command prompt run : [scriptname] /?

Majority of the help files for these tools are self explanatory and you really wouldn't much help even if you are a little accustomed to IIS.

However, I guess I will be writing a detailed post on adsutil, iisweb and iisvdir put together. That should bring more meaning to THIS post. Till then try them out, you will be relieved to see how easy they makes your daily tasks!

Wednesday, August 13, 2008

How to: Install PHP 5 on IIS 7 with FastCGI

While working today I came across my dumped and lost php applications, I use to work on long ago. The moment I saw them I knew I couldn't resist to see them working again. These php code happen to be some of the earliest piece of code I have written. And soon enough it struck me that I had never installed PHP my Vista or on the Windows Server 2008 evaluation copy that I have. Well when better than now! Quickly, I stumbled upon a resource written by Mike and everything worked like a charm. However, I noticed that a lot of people have doubts in various changes that need to be made on both IIS and php.ini

Hence I thought this time instead of writing a step by step instruction guide and confuse all of you, I will show you guys of how it's to be done. Please pardon the voice. I have a few problems with my audio encoder. Having audio for Windows Server 2008 on VMWare Server was in itself a challenge! Check it out!



video

It's also available on YouTube at this location.

The parameters that need to be uncommented in php.ini are:

fastcgi.impersonate
cgi.fix_pathinfo
cgi.force_redirect --> once done change the value to 0 from 1
open_basedir --> put in the physical location of your php applications. (example in the video: c:\inetpub\wwwroot\phpapps)

Let me know if you need any more info on this. I think I might come up with a few more articles or videos on IIS with PHP.

Have Fun!