To access the contents, click the chapter and section titles.
Perl CGl Programming: No experience required.
(Publisher: Sybex, Inc.)
Author(s): Erik Strom
ISBN: 0782121578
Publication Date: 11/01/97
Skill 2 Bringing Perl to the World Wide Web
- Setting up an HTTP server for Windows 95, NT, and UNIX
- Perl meets the World Wide Web
- Examining hellowww.pl
- Perl subroutines
- Using the require command
- CGI and HTML
- The MIME standard
You have done a little with Perl. Now its time to apply what youve learned to the World Wide Web. With very few changes, you can turn a tiny Hello World program into a CGI application that will communicate with any Web browser. Here is the elementary Perl program that you wrote in Skill 1:
#!/usr/bin/perl
print "Hello World!", "\n";
# End hello.pl
However, before you can move your Perl script to the World Wide Web, you need a connection to the Web. You need a Web server. You will learn how to set these things up in this skill.
Setting Up an HTTP Server
You cannot run CGI applications without a Web server, so you need to be connected to or working on a machine that has the server software in place and operating. The vast majority of Web servers in existence are running on UNIX systems; however, Windows 95 and NT are catching up quickly. The chances are very good that your machine will be running one of these operating systems and, for that reason, these platforms will be emphasized in this book.
As for Web server software, there are many choicesand often many handstands required to set them up. Well discuss some of them as they relate to the three operating systems we mentioned.
In general, you have two immediate concerns:
- In what directory does the server expect CGI applications to be?
- How do you enable Perl scripts?
The directory is important for several reasons, not the least of which is so that the server can find the CGI programs. One thing you absolutely never want visitors to see is a strange and, to them, essentially meaningless error message generated because your Perl script isnt where the Web server expects it to be. Security is another important aspect of the CGI directorys location; well discuss some of the security issues in the next section.
The Web server also has to be told what to do with Perl scripts. It doesnt know all by itself that a URL ending in a file with a .pl extension should be invoked as a Perl program.
Running the Sambar Server on Windows 95 or NT
In a world where very few nice things are free, the Sambar Web server (see Figure 2.1) comes as a pleasant surprise. This freeware package runs on Win-dows 95 or NT, can be downloaded in a few minutes and, perhaps best of all, is really a snap to set up. It is a fully functional Web server and its being improved all the time.
Figure 2.1: The Sambar Web site
The Sambar package also includes the latest Win32 version of Perl. Everything you need to get you through the exercises in this book is there in one easy step.
TIP: You can get the free Sambar Web server by pointing your browser to http://www .sambar.com/location.htm.
The file is about 1.5MB and it is zipped; that is, compressed with pkzip. When you unzip it with pkunzip, it will extract a number of files, one of which is called setup.exe. Run Setup and the rest is automatic.
NT and Internet Information Server
If your Web server is running on Windows NT 4.0, you are probably using Microsofts Internet Information Server (IIS), because it comes free with this operating system. Its nice not to have to buy new software, but Microsoft makes you work for it.
Most of Windows NTs configuration information is stored in the Registry; thats where you need to go to answer the two questions we posed earlier:
- In what directory does the server expect CGI applications to be?
- How do you enable Perl scripts?
First, though, you need to start the Registry editor, which will allow you to examine and tweak the Registry. Heres how:
- 1. In NT, click the Start menu at the bottom-left corner of the Desktop, then select Run.
- 2. Type regedt32, then press [return].
These steps will enable you to run the Registry Editor. When it opens, youll see how similar it is to Microsoft Explorer. The window on the left shows the different Registry folders and the window on the right shows the folder contents. To continue the steps,
- 3. Click the window titled HKEY_LOCAL_MACHINE.
- 4. Open the System folder by clicking it.
TIP: When you install Internet Information Server, it will place a shortcut to the server documentation in your Start menu. It makes for a long night, but you really should take the time to read the documentation. Or you can read Mastering Microsoft Internet Information Server X by Peter Dyson (Sybex, 1997).
|