Monday, June 02, 2008

Compile Python 2.5 From Source

Download from Python web page
http://www.python.org/

UnTAR and enter the directory
tar -jxvf Python-2.5.2.tar.bz2
cd Python-2.5.2

Configure using an alternate install dir
(use ./configure -h for config options)
./configure --prefix=/opt/python/

Build and install the software
make | tee makelog
make test | tee maketestlog
make install | tee makeinstalllog
This will create a python binary. If you specified the prefix, it will put it in the bin/ directory under the prefix directory. However, this compiles the command line python version. To get it working with Apache, preform the following.

Download mod_python
http://www.modpython.org/

Untar and enter into the directory
tar -zxvf mod_python-3.3.1.tgz
cd mod_python-3.3.1

Configure mod_python.
It needs to know where python binary to use, and the apache build tool apxs is located during the configure.

./configure \
--with-apxs=/usr/sbin/apxs \ # the apache build tool
--with-python=/opt/python25/bin/python2.5 \ # path to python binary
| tee output.config
make | tee output.make
make install | tee output.makeinstall

make install should place a binary module in /etc/httpd/modules
(or /usr/lib/httpd/modules)
The module will be called mod_python.so

Configure Apache
You will need to tell Apache to load the module by adding the following line in the Apache configuration file (httpd.conf)
LoadModule python_module modules/mod_python.so
<Directory /path/to/somewhere >
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On
</Directory>

Imaging Support

To be able to manipulate images with python, you need the PIL library. Download it from http://www.pythonware.com/products/pil/
After untaring and entering the directory, install by: python setup.py install
It will copy files into your default (`which python`) python install.

http://www.modpython.org/live/current/doc-html/inst-apacheconfig.html