This is a simple guide to install mod_python in cPanel box, running Apache 1.3.x. You need to have Python installed for this to work - most RHEL+cpanel boxes have this installed by default.
1) Download and extract Python:
cd /usr/local/src
wget http://apache.dataphone.se/httpd/modpython/mod_python-2.7.11.tgz
tar zxvf mod_python-2.7.11.tgz
2) Configure & install Python
cd mod_python-2.7.11
./configure --with-apxs=/usr/local/apache/bin/apxs (check where your apxs is by typing: locate apxs)
make
make install
3) Configure Apache
pico -w /usr/local/apache/conf/httpd.conf
Locate your LoadModule - section by pressing CTRL-W and typing "LoadModule". Add the following line under the others:
LoadModule python_module libexec/mod_python.so
Now locate your AddModule - section by pressing CTRL-W and typing "AddModule". Add the following line under the others:
AddModule mod_python.c
4) Installation done, now time for testing!
First go to your public_html directory. Make a test directory for Python by typing:
mkdir python
Now open pico and write the following lines:
AddHandler python-program .py
PythonHandler testingpython
PythonDebug On
save the file as .htaccess.
Now open up pico again and copy/paste the following lines:
from mod_python import apache
def handler(req):
req.send_http_header()
req.write("Hello World!")
return apache.OK
close and save as testingpython.py.
Now restart Apache by typing: service httpd restart
Take your browser to www.mydomain.com/python/testingpython.py and you should see "Hello World!" If you can see this message then you have succesfully installed Python.
Mod_python error
i get this error when i goto testingpython.py
"Mod_python error: "PythonHandler testingpython"
Traceback (most recent call last):
File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 181, in Dispatch
module = import_module(module_name, _req)
File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 335, in import_module
module = imp.load_module(mname, f, p, d)
IndentationError: expected an indented block (testingpython.py, line 4)"
Any Advice??
mistake
ignore...found the problem
Please what was it
I have the same problem. What was your solution? Please.
wrong
This is completely wrong:
from mod_python import apache
def handler(req):
req.send_http_header()
req.write("Hello World!")
return apache.OK
It must be:
from mod_python import apache
def handler(req):
req.send_http_header()
req.write("Hello World!")
return apache.OK
Those are tabs not spaces. If you left align everything like the original code you will get this error:
IndentationError: expected an indented block (testingpython.py, line 4)"
you can use apxs to compile,install and configure mod_python
/usr/local/apache/bin/apxs -cia mod_python.c
This will compile, install and activate(configure) mod_python. You will only need to add the .htaccess after that ;)
-------------------------------------------
One Planet, One Internet!
We Are All Connected!