Lab 8
Web
Servers
Introduction
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.
Instructions:
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:
- Click on the VMWare icon
- Open the file in c:\VM Images\Windows XP\Windows XP
Professional.vmx. You do not
want to “power on” this machine.
- Right Click on the Windows XP Professional Tab (on
the words)
- Go to Snapshot manager. Click on “Initial Configuration with
Perl”, then hit the Go to button.
- Make sure you picked the one with Perl!
- There are a few warning messages...just say yes to
all. If it asks if you moved or
copied the image, click the "I copied it" button
- Loading is very slow – read the rest of the lab
while you wait.
- Once loaded, X out of the small window on the left
so you can see the full width of the screen. Maximize the VMWare window.
- Note that you will now see two taskbars and Start
buttons – one for your actual PC and one for the virtual machine.
- To copy a file from the virtual image to the host
(or vice versa)...just drag and drop
- Now you are ready to do the lab below.
- Important: when finished for the day you must
save a new “snapshot” of the virtual machine – or all your work will be
lost! Save the snapshot as something
like “MIDN Smith Day 1” . After saving your snapshot, you can close
VMWare. Just select “power off” when prompted.
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.
- 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 Lab08. Your
main file should still be called index.html. Verify that you can access
your main file at http://localhost/Lab08/index.html
- Turn on the “rewrite_module” (click on WAMP icon,
then pick “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:
- 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
- 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
- Edit all your Perl files
so that the very first line is: #!c:/Perl/bin/perl.exe
- 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.
12. Demo
#1: Show the instructor that your old website is working inside the virtual
machine.
13. Tip:
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
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:
- As always, your code must be commented! In this case,
you are adding comments to the .htaccess file.
- 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:
http://localhost/Lab08/weather/21401/
and be redirected by the web server to something like
http://localhost/Lab08/query.pl?zip=21401
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
Lab08/index.html is (silently) accessible via some different, nice URL. For
instance, typing in http://localhost/Lab08/swim
into a browser might
transparently fetch the index.html file (the browser still thinks it
fetched Lab08/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 inside C:/wamp, which you will need.
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.
18. Important: before you close VMWare,
save a snapshot! See instructions above.
Deliverables
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