Lab 9

Web Servers





This week we learned how you can control the web server to rewrite/redirect URLs (to provide more useful and stable URLs) and how to do basic access control.  In this lab you will apply all of those concepts.




1.      This lab involves using WAMP – a nicely packaged combo of Apache, MySQL, and PHP for Windows. However, you need to have administrative privileges to run WAMP on your PC – which you probably have in Bancroft but not in the lab.  To address this, we will run WAMP inside a “virtual machine” that will simulate a Windows XP machine where you are an administrator.  We will use VMWare to accomplish this.

2.      Starting up VMWare:

    1. Choose Programs->VMWare->VMWare Player
    2. Open the file c:\Images\Windows XP for IT452\Windows XP Professional.vmx. 
    3. If it asks you if this image was moved or copied, select “I copied it.”
    4. Ignore any warnings about the floppy device – just select OK.
    5. Click (might need to right click) on the Windows XP Professional Tab (on the words)
    6. The machine will start up or boot up.  It may be slow – read the rest of the lab while you wait.
    7. Note that you will now see two taskbars and Start buttons – one for your actual PC and one for the virtual machine. If you don’t see two taskbars, move the VMWare window until you do.
    8. To copy a file from the virtual image to the host (or vice versa)...just drag and drop. Cut and paste will also work (usually).
    9. Now you are ready to do the lab below.
    10. Important: when finished for the day you will just close out VMWare (click on the X in top right corner) and it will save the current state of your machine. If you come back later, you will need to use the same machine.

3.      When finished you will DEMO pieces of your lab to the instructor. 

4.      The instructions below all refer to things you do inside the virtual machine.

5.      Important: Go to C:\wamp\bin\apache\apache2.2.8\conf.  Make a backup copy of httpd.conf (call it httpd.conf.orig)

6.      Load http://localhost in your browser to verify that WAMP is on.  If not, turn it on (From Program Files, run WAMP Server.  An icon will appear at bottom right of your taskbar – left-click on this to verify that it is online. Ask the instructor to demo this if you are confused).

  1. If your Lab07 is not functional (including the Perl parts), talk to the instructor about what to use for the next step.
  2. Copy your Lab07 (from your W: drive) to C:\wamp\www\Lab07 on the virtual machine, then rename it to Lab09. Your main file should still be called index.html. Verify that you can access your main file at http://localhost/Lab09/index.html
  3. Verify that the “rewrite_module” is on (click on WAMP icon, then pick “Apache à Apache modules”)

10.  Modify WAMP settings to get your old functionality working on the WAMP server. If you used relative URLs, then all you need is to enable Perl functionality:

    1. In your httpd.conf file, find this line:
      <Directory "C:/wamp/www">
      Now, below that line, you will see this:
      Options Indexes FollowSymLinks
      Change that line to:
      Options Indexes FollowSymLinks Includes ExecCGI
    2. In your httpd.conf file, find this line:
      AddHandler cgi-script .cgi
      Uncomment it, then modify so you have these two lines:
      AddHandler cgi-script .cgi
      AddHandler cgi-script .pl
    3. Edit all your Perl files so that the very first line is: #!c:/Perl/bin/perl.exe
      (For Apache, the file extension only indicates that the program is some kind of CGI program – it does not tell the web server what kind of CGI program it is. Instead, this line tells it what program, such as Perl, to use).
    4. If you change httpd.conf, do you need to restart the server?

11.  Verify that your old website is now fully functional, via http://localhost, including the Perl aspects. Note that the database portions will still work! (the VM will be accessing the database outside the VM.  Same for your web service). Don’t spend a long time on this! (talk to the instructor if there is some problem).

12.  Demo #1: Show the instructor that your old website is working inside the virtual machine.

13.  Tip: Windows may not directly allow you to create a “.htaccess” file (because the name begins with a period). You can, however, make a file with Crimson Editor or Notepad++ and then save it with this name. Be sure to choose “All files” (not “Text files”) from the file types in the Save dialog window.

14.  Now you will use the web server to make changes. Here is what you what you want to have when you are finished:

    1. As always, your code must be commented! In this case, you are adding comments to the .htaccess file.
    2. Create a re-direct so that one of your Perl files that took an argument in the URL now instead has a nice URL.  For example, you want the user to be able to type in a “nice” URL like:
      and be redirected by the web server to something like
      Use an actual Perl file that is used by your website. You should not change the actual name of your Perl file.
    3. Modify your JS code to make use of the re-direct that you just made, e.g. it no longer directly calls query.cgi but invokes the same program using the “nice” URL instead.
    4. Create a URL re-write so that your main page Lab09/index.html is (silently) accessible via some different, nice URL. For instance, typing in  http://localhost/Lab09/swim into a browser might transparently fetch the index.html file (the browser still thinks it fetched Lab09/swim).
    5. Add “Basic” password protection to your index.html file, via .htaccess. Make at least two users with valid access – one should be “test” with password “test”. Don’t try to enter passwords manually (even with a web script that claims to encrypt them for you – this doesn’t work!).  Instead, start by locating the “htpasswd” program which is somewhere inside C:/wamp. Then use it based on the examples given in class (you run it via the command line prompt, not via double-clicking).  Hmmmm… what does that –c option do?

15.  Ensure your page works with Firefox. Having it work on IE is encouraged but not required.

16.  Demo #2: Show the instructor that the above requirements are working.

17.  For future reference (and turn-in requirements), copy your .htaccess file and the .htpasswd file to your W: drive.


1)      Turn in the following hardcopy on or before the due date, stapled together in the following order (coversheet on top):

a)      A completed assignment coversheet.  Your comments will help us improve the course.

b)      Printout of your .htaccess file

c)      Printout of your password file