Here are the steps to configure mod_python on Apache web server on Debian or Ubuntu Linux:
- Install Apache web server and mod_python package:
sudo apt-get install apache2 libapache2-mod-python
 
- Enable mod_python module:
sudo a2enmod python
 
- Restart Apache web server to apply changes:
sudo systemctl restart apache2
 
- Create a new directory for your mod_python application in /var/www:sudo mkdir /var/www/myapp
 
- Create a new Python script for your mod_python application, for example /var/www/myapp/hello.py. In this script, define a function calledhandlerthat takes two arguments,reqandres. This function will be called by mod_python when a request is received:def handler(req, res):
 res.content_type = 'text/plain'
 res.write('Hello, world!\n')
 return apache.OK
 
- Configure Apache to handle requests to your mod_python application. Edit the Apache configuration file /etc/apache2/sites-available/000-default.confand add the following lines:<Directory /var/www/myapp>
 AddHandler mod_python .py
 PythonHandler mod_python.publisher
 PythonDebug On
 </Directory>
 The AddHandlerdirective tells Apache to use mod_python to handle requests with the file extension.py. ThePythonHandlerdirective tells mod_python to use themod_python.publisherhandler to process requests to your application. ThePythonDebugdirective enables debugging mode for your application.
- Reload Apache configuration to apply changes:
sudo systemctl reload apache2
 
- Test your mod_python application by visiting http://localhost/myapp/hello.pyin your web browser. You should see the message “Hello, world!”.
That’s it! You have successfully configured mod_python on Apache web server on Debian or Ubuntu Linux. Note that mod_python has been deprecated and is no longer actively maintained. It’s recommended to use a different technology, such as mod_wsgi, to run Python applications on Apache.
