Web Hosting Talk







View Full Version : mod_python DSO compilation


case
02-10-2004, 05:06 AM
Ok, this is a really simple way to give your users the ability to run python without recompling apache. Most of this information can be found in the mod_python help files.

PLEASE NOTE:
this tutorial is specific to :

apache 1.3x
mod_python Release 2.7.8 (do not try Release 3.0.4)

====================================================
Side notes:
Chances are, python is already installed on your system. A couple easy way's to check are

Redhat:
root@newyork> rpm -q python
python-2.2.3-5

BSD:
-bash-2.05b$ pkg_info python*

Information for python-2.2.1:

Comment:
An interpreted object-oriented programming language

Required by:
libxml2-2.4.23
p5-XML-LibXML-1.52
libxslt-1.0.19

Description:
Python is an interpreted object-oriented programming language, and is
often compared to Tcl, Perl or Scheme.

If you're having some problems finding python on bsd, you can also try :

-bash-2.05b$ pkg_info | less

hopefully you see something similiar to :

python-2.2.1 An interpreted object-oriented programming language

Being this is not a python installed tutorial, i will not be lending any assistance to those who do not have or cannot get python on there system (this probably isnt you anyways =] )

====================================================

First step:(make sure you're in a comfortable directory)

wget http://mirrors.midco.net/pub/apache.org/httpd/modpython/mod_python-2.7.10.tgz

Second Step:

tar -zxvf mod_python-2.7.10.tgz

Third Step:

cd mod_python-2.7.10

forth step:

./configure --with-apxs=/usr/local/apache/bin/apxs

Fifth step:

make

Sixth Step:

make dso

Seventh Step: ( $su and or sudo prior, if not already root)

make install

Eighth Step: (tell Apache to load the module)
note (use the editor of your choice)

vi /etc/httpd/conf/httpd.conf

or

vi /usr/local/apache/conf/httpd.conf

Find the portion of your httpd.conf file that looks like this :

#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Please read the file http://httpd.apache.org/docs/dso.html for more
# details about the DSO mechanism and run `httpd -l' for the list of already
# built-in (statically linked and thus always available) modules in your httpd
# binary.
#
# Note: The order in which modules are loaded is important. Don't change
# the order below without expert advice.
#
# Example:
# LoadModule foo_module libexec/mod_foo.so

once you have found it, add the line below:

LoadModule python_module libexec/mod_python.so

NOTE:
If your Apache configuration uses ClearModuleList directive, you will need to add mod_python to the module list in the Apache configuration file.

Locate : (usually right below the above mentioned)

# Reconstruction of the complete module list from all available modules
# (static and shared ones) to achieve correct module execution order.
# [WHENEVER YOU CHANGE THE LOADMODULE SECTION ABOVE UPDATE THIS, TOO]
ClearModuleList

once you have found it, add the line below:

AddModule mod_python.c

Nineth Step:

locate :

<VirtualHost xx.xx.xx.xx>
ServerAlias www.xxxxx.com xxxxx.com
ServerAdmin webmaster@xxxxx.com
DocumentRoot /home/xxxxx/public_html
BytesLog domlogs/xxxxx.com-bytes_log
ServerName www.xxxxx.com
User xxxxx
Group xxxxx
CustomLog domlogs/xxxxx.com combined
ScriptAlias /cgi-bin/ /home/xxxxx/public_html/cgi-bin/
</VirtualHost>

directly underneath is add:

<Directory /home/xxxxx/public_html/>
AddHandler python-program .py
PythonHandler mptest
PythonDebug On
</Directory>

change the /home/xxxxx/public_html/ to the folders of users who you want to have this feature. Every user who you want to be able to use mod_python must have their own

Tenth Step:

Restart Apache:

/usr/local/apache/bin/apachectl restart

you may notice:
Loaded DSO libexec/mod_python.so uses plain Apache 1.3 API, this module might crash under EAPI! (please recompile it with -DEAPI)

this is a documented SSL bug and nothing to be concerned with.

Eleventh Step:

Testing it out.. Lets go ahead and get into a web folder you specified in httpd.conf to test this. In my case it's :

cd /home/xxxxx/public_html/

Once were there:

vi test.py

and lets add: (be careful, windows machines like to add useless characters)

from mod_python import apache

def handler(req):
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;req.send_http_header()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;req.write("python is installed!")
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return apache.OK

using your browser, navigate to the test.py file: If you did everything right you should see:

python is installed!

give yourself a pat on the back, update your features list... and enjoy

Doggy
02-10-2004, 03:10 PM
Nice

Pheaton
02-10-2004, 04:39 PM
What exactly is python. Ive heard of it before, but im unclear as to what it is exactly. Is it a programming language or something of the sort?

<edit>signature removed</edit>

case
02-11-2004, 12:33 AM
python is actually quite (for lack of a better word) neat. I also find its a decent primer for beginner programing. If you're interested make your way to:

http://www.python.org/

daveman
02-16-2004, 11:09 PM
Looks good, thanks.

<edit>signature removed</edit>

devilbala
02-17-2004, 06:25 AM
You can get an neat documentation related to mod_python at there website,

As you may know the beauty of mod_python is in it can be linked dynamically with apache rather than re-compiling apache to add this module.

Just 10 minutes work for an professional to do it (If everything went on fine).

Regards,

-Devil