CSCI 330 F06 Scripting Languages

Apache Lab 1 GETTING STARTED

 

1. Log onto one of the Unix machines in the lab

            1.1 Your login userid is your email prefix

            1.2 Your initial password is “cstemp”  You should change your password to something secure at the first opportunity.  You home directory is being hosted remotely on the last machine in the lab.  That machine must always be the first one turned on and must be fully up when the others are started.  Your home directory is exported /export/home/<user name>

 

2. Spend some time playing around with Unix commands (see handout) if you are not familiar with Unix environments.  The lab computers are running Fedora Core 5 which has many improvements that make it have much of the look and feel of GUI environments.  All of the command-line features of Unix are available from Terminal windows which you can open by clicking on the Terminal icon at the top of the window.

 

3. The Objective of this Lab is to achieve familiarity with the Apache Web Server and its configuration file.  The CD that came with your textbook includes Apache 2.0.47.  You can visit httpd.apache.org/download.cgi to obtain Apache for a variety of platforms.  http://httpd.apache.org/ is the URL for the Apache server project.

 

3.1 Open a browser and confirm that Apache is running on your machine by typing /localhost/ as the address in the browser.  You should see a default page.

 

3.2 Apache is configured using the file httpd.conf configuration file.  This is a large text file with all of the Apache Web Server’s configuration information in it.  I am following the textbook (Chapter 21) for this lab and have not had an opportunity to confirm that these examples work in McK-228.  I’ve run them in my office.  You should open the configuration file.  (I’m not sure about permissions at this point so we might have trouble with this.  If we do I’ll copy it and make it available somewhere.)

 

3.3 Scroll through the configuration file to the section that begins with

# Aliases: Add here as many aliases as you need …

(Note: that ‘#’ is the comment delimiter for comments to end of line in the configuration files.  These give information about the configuration file but can be pretty cryptic.)

http://httpd.apache.org/docs/2.0/configuring.html is a tutorial on the Apache site on configuration.

To create an alias, we add the following lines below the comment:

#This alias is for the examples used in Chapter 21

Alias /Chapter21Test “C:/Chapter21Examples”

(Note: This is for Windows OS ¾ when I did it, it didn’t work until I added some tags that created a directory of the form:

<Directory C:/Chapter21Examples> Options Indexes FollowSymLinks </Directory>  ) If changes are made to the configuration file then Apache must be stopped and restarted for the changes to take effect.  We will try to served documents originally from your /home/ directory.  I’m not sure how that will work and we may have to change the configuration files to do it.

 

3.4 Serving Script Generated Documents

In order to run Scripts the scripting languages must be installed.  Perl, PHP, and Python should all be installed on our machines, however I have not verified that so we’ll have to check. If Perl is in /usr/local/bin/perl then the following code in a text file should run:

     #!/usr/local/bin/perl
     print "Wow-Perl runs!\n";
 
See page 702 of your textbook. 
 
3.4.1 Getting Your First Perl-script to run
 
You want to get the test.pl Perl file from the Chapter 21 examples. The following is the contexts of test.pl
 
#!C:\Perl\bin\perl
# Fig. 21.1: test.pl
# Displaying a Perl document on Apache Web Server
 
use warnings;
use strict;
use CGI qw( :standard );
 
my $dtd =
   "-//W3C//DTD XHTML 1.0 Transitional//EN\"
   \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
 
print( header(), start_html( { dtd => $dtd, title => "Test Script" } ),
   h1( "This is a Perl document!" ), end_html() );
 
Executable Perl files need to be in the cgi-bin directory which on Unix systems is in the /usr/local/httpd directory.  Once you’ve put test.pl into that directory you can run it from a browser by pointing the browser at http://localhost/cgi-bin/test.pl


 
 
 
 
 
 
 
 
 
 

   

Congratulations!  You’ve run your first Perl-script.

Now we want to do the same thing with PHP and Python.

 

 

3.4.2 Getting your first PHP-script to run

 

The file test.php is shown below:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns = "http://www.w3.org/1999/xhtml">

   <head>

      <title>A simple PHP document</title>

   </head>

   <body>

      <h1><?php print( "This is a PHP document!" ); ?></h1>

   </body>

</html>

 

To request the file we need to put it into htdocs directory in the /usr/local/httpd directory.  Then you can run it by pointing your browser at http://localhost/test.php and you should see the following rendering in your browser.

 

 

 

 

 

 

 

 

Congratulations you’ve run your first PHP script.

 

3.4.3 Getting your first Python-script to run

The she-bang line (first line) will probably have to be changed but this is the content of the test.py file in the Deitel textbook.  The contents of the she-bang line tell Unix where the python interpreter is located. The file test.py needs to be copied to the cgi-bin directory in the /usr/local/httpd directory.  Then you can point your browser at the file and run it.

 

 

 

 

 

 

 

 

 

 

 

 


Congratulations!  You’ve now run your first Python script.  So new you’ve run a Perl, a PHP and a Python script.  The next thing we have to do if see how to write and run more sophisticated scripts.

 

 

The text of test.py is listed below:

 

#!c:\Python\python.exe

# Displaying a Python document on Apache Web Server

 

testPage = """Content-type: text/html

 

<!DOCTYPE html PUBLIC

      "-//W3C//DTD XHTML 1.0 Transitional//EN"

      "DTD/xhtml1-transitional.dtd">

<html xmlns = "http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

   <head>

      <title>Test Script</title>

   </head>

   <body>

      <h1>This is a Python document!</h1>

   </body>

</html>"""

 

print testPage