Integrating the Apache Web Server and Python

The apache2–mod_pythonmodule embeds the Python environment into the Apache Web server. Embedding this environment avoids the run-time overhead of starting the Python environment externally.

Use the apache2–mod_pythonpackage provided by the Linux distribution.

1.Verify that the apache2–mod_pythonmodule is installed by entering the following command:

#rpm -q python apache2-mod_python

2.Edit the /etc/sysconfig/apache2 file by adding python to the line with

APACHE_MODULES.

After completing this edit, the line should look like the following:

APACHE_MODULES="... ... python"

3.Create the following test file:

/srv/www/htdocs/test.py

Add the following lines to the preceding file from mod_python import apache

def handler(req): req.content_type = 'text/plain' req.write("Hello World!") return apache.OK

4.Edit the following file:

/etc/apache2/conf.d/mod_python.conf

Add the following lines to the preceding file:

<Directory

AddHandler mod_python .py PythonHandler test PythonDebug On

</Directory>

5.Restart Apache by entering the following command:

#/etc/init.d/apache2 restart

6.Verify that Python works by opening a browser and navigating to: http://<YOUR_HOSTNAME>/test.py

The web page displays the following text:

Hello World!

If there are any errors, check the following log files:

/var/log/apache2/error_log /var/log/apache2/access_log

Connecting Tomcat to a Database

Connecting Tomcat to a database requires a JDBC driver for that particular database . The driver is responsible for translating calls from Java programs to the native protocol that is understood by the database. Figure 11 depicts the connection between Tomcat and a database using JDBC.

30

Page 30
Image 30
HP 5991-5565 manual Connecting Tomcat to a Database, Integrating the Apache Web Server and Python