Database Reference
In-Depth Information
Before you can run any scripts in a web environment, your web server must be set up
properly. Recipes 18.2 and 18.3 provide information about doing this for Apache and
Tomcat.
If you run multiple web servers on the same host, they must listen for requests on
different port numbers. In a typical configuration, Apache listens on the default HTTP
port (80) and Tomcat listens on another port such as 8080. The examples here use a
server hostname of localhost to represent URLs for scripts processed using Apache and
Tomcat. The examples use a different port (8080) for Tomcat scripts. Typical forms for
URLs that you'll see in this topic are as follows:
http://localhost/cgi-bin/my_perl_script.pl
http://localhost/cgi-bin/my_ruby_script.rb
http://localhost/cgi-bin/my_python_script.py
http://localhost/mcb/my_php_script.php
http://localhost:8080/mcb/my_jsp_script.jsp
Change the hostname and port number as necessary for pages served by your own web
servers.
18.2. Using Apache to Run Web Scripts
Problem
You want to run Perl, Ruby, PHP, or Python programs in a web environment.
Solution
Execute them using the Apache server.
Discussion
This recipe describes how to configure Apache for running Perl, Ruby, PHP, and Python
scripts. It also illustrates how to write web-based scripts in each language.
There are typically several directories under the Apache root directory. Here I'll assume
that directory to be /usr/local/apache , although it might differ on your system. For ex‐
ample, on Windows, you might find Apache under C:\Program Files . The directories
under the Apache root include bin (which contains httpd —that is, Apache itself—and
other Apache-related executable programs), conf (for configuration files, notably
httpd.conf , the primary file used by Apache), htdocs (the root of the document tree),
and logs (for logfiles). The layout might differ on your system. For example, you might
find the configuration files in /etc/httpd and the logs under /var/log/httpd . Adjust the
following instructions accordingly.
Search WWH ::




Custom Search