November 24, 2003
So you want dynamic content
on your website eh? Well, there are many different scripts and programs
out there that run on Perl. Here's how to setup your webserver to
execute Perl scripts. The examples here are primarily for IIS but
the concepts are the same for other webserver software packages as well.
First thing you need to do
is download the Perl package from ActiveState. Click on the "Download"
button on the left side. If given an option, download a "stable"
version, not the "latest" release. I suggest you download the "MSI"
version instead of the "AS" version since the "AS" version is not uninstallable.
http://www.activestate.com/Products/ActivePerl
The version I downloaded
is named: ActivePerl-5.6.1.633-MSWin32-x86.msi
Double click on the file
you just downloaded and let's install it.
You'll see this screen.
Click "Next".
The License Agreement comes
up. Read it and check the "I accept" radio button and click the "Next"
button.
You'll see this screen:
You can choose which packages
you want. I just want the Perl interpreter so I'm going to uncheck
the rest of the boxes. You can also choose the install location of
the program. "C:\Perl" is selected by default but you can choose
whichever directory you want. I'm going to keep it at default.
Read this next message and
click "Next".
Here the installation adds
a mapping to IIS. You can leave all of the boxes checked. Click
"Next".
Now we can begin the installation.
Click "Install".
You'll see the progress status.
When the installation is
done, you'll see this. Click "Finish".
The documentation for Perl
can be found at:
Start -> Programs -> ActiveState
Active Perl 5.6 -> Documentation
You're now done. If
you are using IIS, Perl should automatically be installed into the webserver.
However, there are still a bunch of things we need to setup.
Start -> Settings -> Control
Panel -> Administrative Tools -> Internet Services Manager
Right-click on your server
and select "Properties".
By editing these master properties,
all the subsequent websites will automatically have the Perl interpreter
properly setup as well. Click on "Edit".
You'll see this:
Click on the "Home Directory"
tab.
Click on the "Configuration"
button. You'll see the settings for IIS and how it handles files
with different extensions.
Scroll down to the bottom
of the list. You'll see two new entries for Perl.
Let me try to explain what
we're looking at. Here, any file with a ".pl" extension will be processed
by "c:\perl\bin\perl.exe". Any file with a ".plx" will be processed
by "c:\perl\bin\perlis.dll". What's the difference between "perl.exe"
and "perlis.dll"? "perlis.dll" is Perl for ISAPI, an IIS plug-in
that makes Perl CGI faster. It's designed specifically for IIS.
However, if you are using Apache or some other webserver, use the "perl.exe".
Now, I'm going to suggest
something if you are using IIS for your webserver software. I'm going
to suggest that you change the ".pl" extension from "perl.exe" to "perlis.dll".
I do this because "perlis.dll" is faster than "perl.exe". Now, you
can choose to do this if you want or you can leave it the way it is.
So if you want to change
it, this is how you do it. If you DO NOT want to change this, skip until
you see this # mark. (Low tech eh?)
Click on the ".pl" line.
Click on "Edit".
At the first line, click
on "Browse". Go to the directory where Perl is located and find "perlis.dll".
You'll have to change "File of type" to "All files (*.*)" to see the file.
Click on "OK" until you get
back to the original screen.
# <--
Everybody starts again here.
Now we have to add a extension
mapping for ".cgi". Click on "Add".
Fill out the blanks so it
looks like this:
You should see this now:
Now click "OK" to close this
window. You'll see this screen:
Click the "Select All" button
and then "OK".
Close all the windows and
let's see if this thing works.
Open up Notepad.exe and copy
the text between the two red lines and paste them into a blank document.
--------------------------------------------------------------
#!/usr/bin/perl
#
Alert! The web server is *NOT* processing the script if you can read this
line.
print
"Content-type: text/html\n\n";
print
"Hello world from PERL $]\n";
--------------------------------------------------------------
In Notepad "Save As" and
type in "hello.cgi". Include the quotations marks. This tells
Notepad to put the extension you specify on the file instead of the normal
".txt". Save As again, this time as "hello.pl". Then Save As
one last time as "hello.plx".
You just should have created
3 files: hello.cgi, hello.pl, and hello.plx.
Put these files into your
directory and fire up your web browser to call each file individually.
You should see this message. Each file will test whether that particular
extension is working or not.
Now let's talk about some
settings for your webserver. In IIS, you can control which websites
and directories allow running scripts (Perl or executables) or not.
For example, you may want to set it so that your whole website does not
allow Perl scripts to run except for those scripts that are located in
a specific directory you specify. In general, it is a good idea to
control where scripts can and cannot be run. It tightens up the security
on your server a bit.
Let's go through an example.
We'll use a website called "TempHost.com" as an example. The goal
of this example is that we don't want scripts or executables to be run
in "TempHost.com" except for the directory of "cgi-bin". The directory
doesn't actually have to be called "cgi-bin". It can be named anything
you want. "cgi-bin" is a just a historically common name for a directory
that holds Perl scripts.
In Internet Information Services,
right click on "TempHost.com" and select "Properties".
Go to the "Home Directory"
tab. At the section that says "Execute Permissions", select "None".
Now click "OK" until you
get to the main screen again. Now, right click on the "cgi-bin" directory
and select "Properties".
Under the "Directory" tab,
change the "Execute Permissions" to "Scripts and Executables". If
you only have scripts, you can select "Scripts Only". Click "OK".
Now, you can test use the
"hello" scripts to see if what we just did worked. If everything
worked out correctly, the "hello" scripts will not work in any of the directories
except for the ones you gave permissions to. In our example, Perl
scripts should only run in "cgi-bin".
That's about it. Now,
if you're using different webserver software, you'll have to do the mappings
yourself. Basically you have to setup the Perl application (perl.exe)
to the proper script extension (.cgi and .pl and .plx)
.cgi = perl.exe
.pl = perl.exe
.plx - perl.exe
Good luck!
Brian
|