Using Apache to Run Web Scripts
Problem
You want to run Perl, PHP, or Python programs in a web environment.
Solution
Execute them using the Apache server.
Discussion
This section describes how to configure Apache for running Perl, PHP, and Python scripts, and illustrates how to write web-based scripts in each language.
There are typically several
directories under the Apache root directory, which
I’ll assume here to be
/usr/local/apache. These directories include:
binContains httpd—that is, Apache itself—and other Apache-related executable programs
confFor configuration files, notably
httpd.conf, the primary file used by ApachehtdocsThe root of the document tree
logsFor log files
To configure Apache for script execution, edit the
httpd.conf file in the conf
directory. Typically, executable scripts are identified either by
location or by filename suffix. A location can be either
language-neutral or language-specific.
Apache configurations often have a
cgi-bin directory under the server root
directory where you can install scripts that should run as external
programs. It’s configured using a
ScriptAlias directive:
ScriptAlias /cgi-bin/ /usr/local/apache/cgi-bin/
The second argument is the actual location of the script directory in
your filesystem, and the first is the pathname in URLs that
corresponds to that directory. Thus, the directive just shown
associates scripts located in
/usr/local/apache/cgi-bin with URLs that have
cgi-bin following the hostname. For example, if you install the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access