Algorithms
Verified User
- Joined
- Aug 31, 2005
- Messages
- 6
This is currently deployed on our DA server.
This assumes you have the ports collection installed.
Comments, Suggestions, Improvements welcomed.
Green text is commands and output from the console
Orange-red text is for log and error information
Dark blue is for file contents
I recently upgraded from Apache 1.3.x and mod_python 2.7 to Apache 2.0.59 and mod_python 3.2.8. Here is an update to my old HOWTO
This is how I did it on FreeBSD 5.3-RELEASE
First we need a fresh build of Python without thread support. If you tried to install mod_python previously and got a message like this.
Cannot load /usr/lib/apache/mod_python.so into server:
/usr/lib/apache/mod_python.so: Undefined symbol "pthread_attr_init"
That means the Python you compiled mod_python against had threads enabled. To fix this, we need to edit our Python port and reinstall. Make sure to cvsup your ports collection before installing the new Python.
$ cd /usr/ports/lang/python
$ su
$ make clean
$ WIHTOUT_THREADS=1 make install
$ exit
Note: You may need to run a make deinstall before running make install.
Once Python is installed without threads, you can test by running the shell and attemping to import thread, you should get an error.
$ python
Python 2.4.3 (#2, Sep 18 2006, 11:42:14)
[GCC 3.4.2 [FreeBSD] 20040728] on freebsd5
Type "help", "copyright", "credits" or "license" for more information.
>>> import threads
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named threads
>>>
Now we can install mod_python. Download and extract the mod_python 3.2.8 source.
$ cd ~/
$ fetch "http://mirror.candidhosting.com/pub/apache/httpd/modpython/mod_python-3.2.8.tgz"
$ tar -zxvf mod_python-3.2.8.tgz
$ cd mod_python-3.2.8
$ ./configure
$ make
$ su
$ make install
Now we have the mod_python module installed without threads and we are able to restart apache, but first we need to comment out the mod_python line in the httpd.conf
$ vi /etc/httpd/conf/httpd.conf
LoadModule python_module /usr/lib/apache/mod_python.so
Uncomment or add this line if you don't have it. Save and exit.

I logged in to DA as admin and restarted the httpd service that way. I prefer that over doing it in the shell.
Now, go to the directory where you want to use mod_python and create a .htaccess file
$ cd /home/user/domains/test.com/public_html
$ vi .htaccess
In that file, place the following lines. (Alter to fit your needs)
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonOption session DbmSession
PythonOption session_dbm /home/user/domains/test.com/session.dbm
PythonOption ApplicationPath /
PythonDebug On ## Turn this off when done with debugging
DirectoryIndex index.py
Now you can create a test file in the directory. Mine looked like this.
Code:
## index.py
from mod_python import apache
def index(req):
req.content_type = 'text/plain'
req.write('Hello from mod_python\n')
return apache.OK
Pull this up in your browser, if you see the works Hello from mod_python followed by a zero (0) you have successfully installed mod_python.
Enjoy
Last edited: