Chapter 8. Dynamic Content

CGI programs are one of the simplest ways to provide dynamic content for your web site. They tend to be easy to write, because you can write them in any language. Thus, you don’t have to learn a new language to write CGI programs.

Other dynamic content providers, such as PHP and mod_perl, also enjoy a great deal of popularity, because they provide many of the same functions as CGI programs but typically execute faster.

Very few web sites can survive without some mechanism for providing dynamic content—content that is generated in response to the needs of the user. The recipes in this chapter guide you through enabling various mechanisms for producing this dynamic content and help you troubleshoot possible problems that may occur.

8.1. Enabling a CGI Directory

Problem

You want to designate a directory that contains only CGI scripts.

Solution

Add the following to your httpd.conf file:

ScriptAlias /cgi-bin/ /www/cgi-bin/

Discussion

A CGI directory will usually be designated and enabled in your default configuration file when you install Apache. However, if you want to add additional directories where CGI programs are permitted, the ScriptAlias directive does this for you. You may have as many ScriptAlias‘ed directories as you want.

The one line previously introduced is equivalent to these directive lines:

Alias /cgi-bin/ /www/cgi-bin/

<Location /cgi-bin/>
    Options ExecCGI
    SetHandler cgi-script
</Location>

Warning

Note that URLs that map to the directory in question ...

Get Apache Cookbook 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.