Lab 9
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:
- 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 select
OK.
- 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.
- 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 will just
close out VMWare (click on the X in top right
corner) and it will save the current state of your 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).
- 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
- 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. Note that the database portions will still work! (the VM will be accessing the database outside the VM. Same for your web service). This should not
take long – 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 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/Lab09/weather/21401/
and be redirected by the web server to something like
http://localhost/Lab09/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
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. 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.
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