lost and found ( for me ? )

Apache : mod_python



Here’s how to use mod_pyhon on Ubuntu 12.04 apache.

just referred to the following tutorial.many thanks!


root@ubuntu-vm2:~# tail -1 /etc/lsb-release ;uname -ri
DISTRIB_DESCRIPTION="Ubuntu 12.04.2 LTS"
3.2.0-49-virtual x86_64

install apache2, mod_python
root@ubuntu-vm2:~# apt-get install apache2  libapache2-mod-python

to use python within Apache, there are two ways, publisher handler or PSP hander.

The Publisher handler allows access to functions and variables within a module via URLs.

The PSP handler processes text documents with Python code embedded between <% and %> tags

[ publisher handler ]

edit
# vi /etc/apache2/sites-available/default

add the red lines.
       </Directory>
       <Directory /var/www/>
               Options Indexes FollowSymLinks MultiViews
               AllowOverride None
               Order allow,deny

               # add for mod_python
               allow from all
               allow from allddHandler mod_python .py
               PythonHandler mod_python.publisher
               PythonDebug On
       </Directory>

when there is not “allow from all” line, I got the error “403 forbidden”

restart apache2
# service apache2 restart

make a python script file for testing.
root@ubuntu-vm2:~# cat /var/www/test.py
def index(req):
return "hello!";



root@ubuntu-vm2:~# ls -l /var/www/test.py
-rw-r--r-- 1 root root 34  7月 21 09:28 /var/www/test.py

access to http://Apache’s IP/test.py

[ PSP handler ]

edit default.
root@ubuntu-vm2:~# vi /etc/apache2/sites-available/default



DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny

# add for mod_python
# allow from all
# AddHandler mod_python .py
# allow from allddHandler mod_python .py
#               PythonHandler mod_python.publisher
#               PythonDebug On

# add for mod_python ( PSP handler )
allow from all
               AddHandler mod_python .psp
               PythonHandler mod_python.psp
               PythonDebug On
</Directory>



restart apache2
# service apache2 restart

prepare psp file

root@ubuntu-vm2:~# cat /var/www/test.psp
<html>
<body>
<h1><% req.write("Hello!") %></h1>
</body>
</html>
root@ubuntu-vm2:~#
root@ubuntu-vm2:~# ls -l /var/www/*.psp
-rw-r--r-- 1 root root 65  7月 21 12:25 /var/www/test.psp



access to the psp file.




No comments:

Post a Comment

Note: Only a member of this blog may post a comment.