Dynamic Content

The most common way to provide dynamic content on websites is with CGI programs. CGI is a specification of communication between server processes (such as programs that generate dynamic documents) and the server itself. SSIs allow output from CGI programs, or other programs, to be inserted into existing HTML pages.

Another way to add dynamic content to your website is to use PHP (PHP Hypertext Preprocessor [the name is recursive]). PHP is an HTML-embedded scripting language designed specifically for web usage. The PHP module for Apache is one of the most popular third-party modules available.

By default, you can put any CGI program on your server in the directory defined by the ScriptAlias directive.

CGI programs can be written in any language. The most popular languages for CGI programming are Perl and C. Chapter 27, "Using Perl," provides more information about using the Perl scripting language.

These programs must be executable by the default Apache user, which means you must change the mode of the files to 555 so the Apache user can execute them. By default, Apache runs in Ubuntu as a user named apache:

chmod 555 program.cgi

To execute CGI programs outside the scriptAlias directory, you must enable the ExecCGi option for that directory. This is done either in your httpd.conf file or in an .htaccess file in the directory.

To test whether you have CGI configured correctly, try the CGI program in Listing 20.1. This program is written in Perl and displays the values of the HTTP environment variables.

Listing 20.1. environment.pl

"Content-type: text/html"

<TITLE>Simple CGI program</TITLE> </HEAD> <BODY> EOF

If you're going to write CGI programs in Perl, take some time to study the CGI modules that come bundled with Perl. An extensive Perl module library, which contains many modules designed to be used when writing CGIs, is accessible at http://www.cpan.org.

If you are using many CGIs written in Perl, examine the mod_peri module. It embeds a Perl interpreter within the Apache server. Using this module results in faster execution times for your CGIs because you don't need to start a new Perl interpreter for each request. You will find information about using mod_peri under the /usr/share/doc/_mod_peri-1.99_12/docs/ directory if you install it from this book's CD-ROMs.

Was this article helpful?

0 0

Post a comment