Integrating the Apache Web Server and Python
The
Use the apache2–mod_python package provided by the Linux distribution.
1.Verify that the
#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