Chapter 18. Serving Perl Pages to the Web

In this chapter, we’ll see how to write simple web database clients using Perl. Web applications written using Perl can take advantage of the Apache module mod_perl and the HTTP::Mason library for robust and high-performance web sites. We don’t discuss these in detail in this book. We should note that unlike Perl, PHP was designed from the start to be used for scripting web pages and is probably a better choice for any major new web application.

In Chapter 2, we saw how to install the Apache web server on a Linux system, and the XAMPP package on Windows and Mac OS X. We can make our Perl scripts accessible from a web server by placing them in a location that the web server can access.

On a Linux system, the scripts should be placed in the cgi-bin directory under the web server document root, typically /var/www/cgi-bin or /usr/local/apache/htdocs/cgi-bin. For a Windows system, the scripts should be placed in C:\Program Files\xampp\cgi-bin. For a Mac OS X system using XAMPP, use /Applications/xampp/htdocs.

Depending on the system configuration, you may need to have system root or administrator privileges to write files to this location. You can assume these privileges under Linux by typing su -, under Windows by logging in as a user with Windows Administrator privileges, or under Mac OS X prefacing commands with the sudo keyword.

Let’s write a small script to generate the following HTML page:

<html> <head> <title>My first Perl CGI script</title> ...

Get Learning MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.