Thursday, October 21, 2010

Use IIS to serve websites from your Windows 7

Thursday, 11PM. I was cleaning up my desk, getting ready for my lunch break, when the Marketing Manager stepped into my office.

"Ohai! All ready for your gaming expo?" I asked her casually.

"Yep, pretty much. We're also set for a survey-slash-raffle program, where our booth visitors can fill in their contact info and play a jackpot-machine minigame to get into the instant raffle."

"That sounds gr---" I tried to reply, but she kept on going.

"It's a flash webpage, and we're using Microsoft Access as the database storage. So we'll run everything off the browser on our two laptops. They both are running on Windows 7."

Suddenly I had a funny feeling down my brain. "Sooo... you want me to copy the program files to our website?" I asked, trying to guess where this talk led to. "No problemo!"

"Actually, THAT'S the problem..." she told me, sighing. "We won't have any internet access in the expo. And we're leaving by 3..."

Aha! So my feeling was right. Being a helpful coworker, I gave her a promise worthy of the next Presidential candidate: "Give me your laptops, and in 30 minutes I'll make it work locally."

And there she went, dashing to her office and back, presenting me with 2 high-end laptops and a big wide smile on her face.

So how did I tackle this? With the help of Microsoft's IIS, it's super easy! Follow these steps, and you can do it too!


Introduction to IIS

Before I go on with the steps, allow me to briefly explain about IIS (Microsoft's Internet Information Services). To cut it short: IIS is Microsoft's web server (and a web server is a collection of services to let you serve your websites). In Windows 7, IIS is offered as a 'Personal Web Server' component, available on all Windows 7 editions except Home Basic and Starter. For more information on IIS, please visit The Official Microsoft IIS Site or this Wikipedia article.

Now, off we go!


First, check the OS

I knew it's Windows 7 (she told me, remember?), but I needed to make sure the edition. If it's Home Basic or Starter (which I doubted, considering they're high-end laptops), then I had to think of Plan B. Anyway, Win+Pause/Break I went (FYI in case you don't know, that's the shortcut key to bring up the System info, a.k.a. System Properties), and---yeah!---they were Home Premiums.

System Info

Yay! Knowing I can stick to my plan, I proceeded to the next step...


Installing IIS

IIS is not installed by default, so I had to go to the the Control PanelProgramsTurn Windows features on or off (under Programs and Features section), and checked the Internet Information Services checkbox.

Installing IIS

While there, I made sure I had the ASP component checked as well, because that game program were written in ASP. If your web files are all .HTM/HTML (including JS, CSS, XML, PNG, JPG, GIF, and all the other 'static' files), then you don't need to enable this.

An OK later, it started the installation, and finished everything in several seconds. Or was it?


Testing the installation

There's only one way to be sure: I fired up the browser (I used the stock Internet Explorer 8) and typed the local address:
http://localhost/
(localhost is an alias for your own computer, which translates to 127.0.0.1)

Taa daa! I could see the IIS welcome page!

Testing IIS installation

From the IIS Manager (SitesDefault Web SiteBasic settings) I grabbed the website location, which was in:

C:\inetpub\wwwroot\

Default Web site - Basic settings

(in other words, http://localhost/ translates to C:\inetpub\wwwroot\)

Then I simply proceeded to copy the game program files into a subfolder called TigerGame(20100731), so the URL for this game's root will be:

http://localhost/TigerGame(20100731)/

That's all, folks! Except that it won't work on the database part. Oh well :(


MDB access additional setup #1: Enabling 32-bit application mode


In case you didn't notice, the laptops' operating systems were 64-bit, which is great. However, there's currently no way to make the ASP program work with Microsoft Access' MDB file. Perhaps ODBC/OLEDB 64-bit drivers are missing, but this was not a good time to do research and experimentation. (Also I read somewhere looong time ago that the 64-bit drivers were either buggy, beta version, or simply just don't work).

So in order to make it work, the easiest and proven solution was to 'downgrade' IIS application pool to 32-bit mode: Application PoolsDefaultAppPoolAdvanced settings → set Enable 32-bit Applications to True.

Enabling 32-bit Applications

(note that the application pool used by the website was DefaultAppPool, where you can get from the website setting dialog window).

And now it worked! But---ohnoes!---it wouldn't save anything to the database. Solution: check the permission!!!


MDB access additional setup #2: Make the MDB writable


Permission is given to a user (or a group) and assigned to a resource (e.g. a file). So for this case, I need to give the 'anonymous user' account a write permission to the database file.

So first thing first: I need to check what's the 'anonymous user' account: Default Web siteAuthenticationAnonymous AuthenticationEdit.

Checking the anonymous account name

There I could see the account was named 'IUSR'. Then I proceeded to give this user a write permission to the database file, which I found to be named db_store.mdb: Right click on the file → PropertiesSecurityAdd → typed 'IUSR' and OK-ed it → and set the permission as below:

Setting file permission for the anonymous account

That's it! After OK-ing the dialog boxes, I tested the back-end interface of the game (where I could directly try updating the database), and... SUCCESS!!!

Success!


TL;DR


In this post, I demonstrated that your Windows 7 can easily be 'turned' into a web server (albeit perhaps better be for personal/development purposes only). The process was relatively easy and straighforward. And if you want to try, I'm sure you can accomplish this in less than 30 minutes! Awesome, huh?

Questions? Problems? Leave a comment and I'll try my best to help.

No comments:

Post a Comment