IIS, PHP, and MySQL on Server Core

One of the Server Core roles of Windows Server 2008 that will likely get the most usage is that of IIS Web Server. Already the second most popular web server behind only Apache (see most recent Netcraft survey), IIS running on Server Core may end up being a winning combination for Microsoft. Apache is typically run on top of the Linux OS in tandem with MySQL and PHP, a setup referred to as a LAMP server (Linux, Apache, MySQL, PHP). I had the need for such an environment in a recent project, and with the reduced attack surface, smaller footprint, and the improved IIS 7, I decided to see if Server Core could take the place of Linux in that equation. It’s a setup called a WIMP server (Windows, IIS, MySQL, PHP)… okay, so maybe the acronym needs some work.

Step 1 – Server Core

The first step is to install Server Core and configure it to your liking. I’m not going to cover those details in this post, but if you need assistance see my previous post on Server Core administration. Do the obvious stuff: give it a name, a static IP, configure time/date, etc.

Step 2 – IIS Server Role

The next step is to install the roles required to run web services. Installing IIS 7 is a bit different than IIS 6; doing so in Server Core with no GUI adds some complexity. I researched the steps for doing so and will show them here without explaining them in depth (not sure I could anyway). If you want to learn more, I suggest IIS.net or TechNet.

You use ocsetup to install the required roles with the following command:

start /w ocsetup IIS-WebServerRole;WAS-WindowsActivationService;WAS-ProcessModel;IIS-CGI

Once that completes, you should have a functioning web server which you can verify by connecting to your server with a web browser. You should see the IIS7 splash page. You can also drop a basic test HTML file in c:\inetpub\wwwroot and browse to http://server/test.htm to confirm operation.

Step 3 – Install PHP / Configure IIS PHP Support

Installing PHP isn’t nearly as difficult as it used to be just a few years ago. With better native support, IIS 7 also makes things a bit easier. I used the current PHP release (ver 5.2.6) with no problems. You’ll want to download the zip package from here and extract the contents to c:\php on your Server Core box.

Once the files are in place, make a copy of the ‘c:\php\php.ini-recommended’ file, and name it ‘c:\php\php.ini’. Configuring the php.ini file can be a daunting task if you’ve never done so before. I suggest researching the various settings to understand the implications, however, the settings below will get PHP working on IIS. Open php.ini in notepad, make the changes, then save the file. Where I’ve written “Set” means to change the variable’s value, “Uncomment” means to remove the semi-colon preceding the variable.

Set: error_reporting = E_ALL & ~E_NOTICE
Set: extension_dir=”c:\php\ext”
Uncomment, Set: cgi.force_redirect = 0
Uncomment: fastcgi.impersonate = 1
Uncomment: fastcgi.logging=0
Uncomment: extension=php_mysql.dll

You now need to create a PHP handler so IIS knows how to interpret .php files. This is done with the appcmd.exe tool located in %windir%\system32\inetsrv (not in the PATH, so run it fully qualified). The following commands are case sensitive!

appcmd set config /section:system.webServer/fastCGI /+[fullPath=’c:\php\php-cgi.exe’]

appcmd set config /section:system.webServer/handlers /+[name=’PHP-FastCGI’,path=’*.php’,verb=’*’,modules=’FastCgiModule’,scriptProcessor=’c:\php\php-cgi.exe’,resourceType=’Either’]

Both commands should return a message stating that config changes were applied. You should now have a functioning web server capable of handling PHP pages. This can be confirmed by creating a test PHP file in your wwwroot directory with the following contents:


You should then be able to browse to http://server/phptest.php and see a page showing the descriptive output of the phpinfo() function. Further configuration of the php.ini file may be necessary depending on the web applications you decide to run.

Step 4 – Install MySQL

Again, this is a task that isn’t nearly as difficult as I remember it being several years ago when I first worked with MySQL. There are different versions and different editions of MySQL, I used the most recent version, v6.0.7 Community Edition, Essentials package. The Essentials package is about half the size of the Complete Package as it doesn’t include many optional components. The download link for it is here.

Once downloaded to your Server Core box, run the .msi installer and proceed through the GUI setup. You’ll want to choose the typical settings. When installed, choose the option to run the configuration wizard, choose the Standard configuration, choose to install it as a Windows service, and choose the option to include the bin directory in the Windows path. Set the root dba password, execute the configuration settings, and you’re done. The MySQL service will have started, but a reboot here wouldn’t hurt to confirm service auto-start and to make the change to %PATH% take effect.

Verify MySQL operation by logging in using the mysql.exe command. From the command prompt type:

mysql -u root -p

You’ll be prompted for the root password configured during installation. Once logged in type the following command at the mysql prompt:

mysql> show databases;

You should see a list of system databases, confirming that MySQL is running. You can create a database using the “create database <dbname>;” command.

Congratulations, if you completed these steps, you now have your own WIMP server. I’m not going to go into working with MySQL or writing PHP as they’re both beyond the scope of this article, but if you need assistance check out the MySQL Reference Manual or PHP.net. Of course you can also run this setup with a slightly different configuration, using a different DBMS like SQL Server or Oracle, or even using Apache instead of IIS.

Check back soon for my next post where I’ll discuss the project that required this setup in the first place, running the Snort IDS and BASE security analysis engine on Server Core 2008.

Subscribe to TechScrawl via RSS


3 Responses

  1. Great post, I’ll try to do this very soon.

  2. Nice post u have here :D Added to my RSS reader

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: