Install and Configure Mod_Python With Apache 2
In this tutorial i assume you already have Apache 2.x , PHP 5.2.x and MySQL 5.x installed and running in your server.
If your server is a brandnew server. You need to follow this URL to install a complete Apache, PHP and MySQL
What is Mod_Python ?
Mod_python is an Apache module that embeds the Python interpreter within the server. With mod_python you can write web-based applications in Python that will run many times faster than traditional CGI and will have access to advanced features such as ability to retain database connections and other data between hits and access to Apache internals.
Preparing to Install and configure Mod_Python
Login into your server with root access
#cd /root
#wget http://www.python.org/ftp/python/2.5/Python-2.5.tgz
#wget http://www.eu.apache.org/dist/httpd/modpython/mod_python-3.2.10.tgz
#wget http://downloads.sourceforge.net/project/flex/flex/flex-2.5.35/flex-2.5....
Extract Sources
#tar -zxvf Python-2.5.tgz
#tar -zxvf mod_python-3.2.10.tgz
#tar -zxvf flex-2.5.35.tar.gz
Install flex
#cd flex-2.5.35
#./configure
#make
#make install
Install Python
#cd Python-2.5
#./configure --enable-shared
#make
#make install
Try to access python with this command below :
#/usr/local/bin/python
if you can see a python prompt its mean you are successfully installed python on the server.
if you see any lib error or can't find lib. you need to run ldconfig and try accessing the command above
#ldconfig
Install Mod_Python
#cd mod_python-3.2.10
#./configure --with-apxs=/usr/local/apache2/bin/apxs \
--with-python=/usr/local/bin/python2.5 \
--with-flex=/usr/local/bin/flex
#make install_dso
#make install_py_lib
It will automatically install mod_python.so to /usr/local/apache2/modules
Configure Apache to Support Mod_Python
#vi /usr/local/apache2/conf/httpd.conf
####Add this lines below####
LoadModule python_module modules/mod_python.so
### Example Virtual Host ###
<VirtualHost 10.10.10.10>
ServerName testing.com
ServerAlias www.testing.com
DocumentRoot "/home/domains/testing.com/htdocs"
<Directory "/home/domains/testing.com/htdocs">
<IfModule mod_python.c>
AddHandler mod_python .py .psp
PythonHandler mod_python.publisher | .py
PythonHandler mod_python.psp | .psp
</IfModule>
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Restart Apache Webserver
#/usr/local/apache2/bin/apachectl stop
#/usr/local/apache2/bin/apachectl start
Create testing.py in /home/domains/testing.com/htdocs for publisher handler
#cd /home/domains/testing.com/htdocs
#vi testing.py
def index(req):
return "Test successful";
Create testing.psp /home/domains/testing.com/htdocs forPSP handler
#vi testing.psp
<html>
<body>
<h1><% req.write("Hello!") %></h1>
</body>
</html>
Try to access testing.py through browser
http://testing.com/testing.py and you will see a Test successfull print in the browser
Try to access testing.psp through browser
http://testing.com/testing.psp and you will see a BOLD/HEADER with Hello print in the browser
Note: mod_python seems to have a bug in few version so if there is a bug on the mod_python try to using CVS / SVN version.
NOTE:
I've successfully applied mod_python with apache2 in centos server. so i assume this will also working with your server with centos server.
if you have any problem with mod_python, try to install mod_python with SVN/CVS version.
Recent blog posts
|
Recent comments
|
Comments
Post new comment