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.
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.
Starting up VMWare:
- Choose Programs->VMWare->VMWare Player
- Open the file c:\Images\Windows XP for IT452\Windows XP Professional.vmx.
- If it asks you if this image was moved or copied,
select “I copied it.”
- Ignore any warnings about the floppy device – just
- Click (might need to right click) on the Windows XP
Professional Tab (on the words)
- The machine will start up or boot up. It may be slow – read the rest of the
lab while you wait.
- 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.
- To copy a file from the virtual image to the host
(or vice versa)...just drag and drop. Cut and paste will also work
- Now you are ready to do the lab below.
- 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.
When finished you will DEMO pieces of your lab to the
The instructions below all refer to things you do inside
the virtual machine.
Make a backup copy of httpd.conf (call it httpd.conf.orig)
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).
- If your Lab07 is not functional (including the Perl
parts), talk to the instructor about what to use for the next step.
- 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
- Verify that the “rewrite_module” is on (click on WAMP
icon, then pick “Apache à Apache modules”)
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:
- In your httpd.conf file,
find this line:
Now, below that line, you will see this:
Change that line to:
Indexes FollowSymLinks Includes ExecCGI
- In your httpd.conf file,
find this line:
Uncomment it, then modify so you
have these two lines:
AddHandler cgi-script .cgi
AddHandler cgi-script .pl
- 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).
- If you change httpd.conf,
do you need to restart the server?
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).
#1: Show the instructor that your old website is working inside the virtual
Windows will may not directly allow you to create a “.htaccess” file. You can,
however, make a file with Crimson Editor and then save it with this name. Be
sure to choose “All files” (not “Text files”) from the file types in the Save
you will use the web server to make changes. Here is what you what you want to
have when you are finished:
- As always, your code must be commented! In this
case, you are adding comments to the .htaccess
- 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.
- Modify your JS code to make use of the re-direct
that you just made, e.g. it no longer directly calls query.pl but invokes the same
program using the “nice” URL instead.
- 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).
- 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?
your page works with Firefox. Having it work on IE is encouraged but not
#2: Show the instructor that the above requirements are working.
future reference (and turn-in requirements), copy your .htaccess file and the .htpasswd
file to your W: drive.
Turn in the following hardcopy on or before the due
date, stapled together in the following order (coversheet on top):
A completed assignment coversheet. Your comments will help us improve the
Printout of your .htaccess file
Printout of your password file