Mobile app version of vmapp.org
Login or Join
Mendez628

: Parse Python script on Apache virtual host I have an up and running Apache server working with PHP on a Centos 6 server. Apache was installed using yum -y install httpd mod_ssl. I now

@Mendez628

Posted in: #Apache #Centos #Python

I have an up and running Apache server working with PHP on a Centos 6 server. Apache was installed using yum -y install httpd mod_ssl. I now wish to add Python.

I installed Python as follows:

wget python.org/ftp/python/3.3.5/Python-3.3.5.tar.xz tar xf Python-3.3.5.tar.xz
cd Python-3.3.5
./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall


I installed mod_python using yum install mod_python.

/etc/httpd/conf/httpd.conf includes the following line Include conf.d/*.conf, so then I know that /etc/httpd/conf.d/python.conf has been included. I made no changes to /etc/httpd/conf.d/python.conf, and the only un-commented directives are:

LoadModule python_module modules/mod_python.so
<Directory "/var/www/manual/mod/mod_python">
<Files *.html>
SetHandler default-handler
</Files>
</Directory>


I then added the following VirtualHost.

<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/python/html
<Directory /var/www/python/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
</Directory>
AddHandler mod_python .py
#DirectoryIndex index.html index.php index.py
</VirtualHost>


If I access example.com/testphp.php, it is parsed as PHP, however, if I access example.com/testpython.py, it returns a 404 Not Found error. If I comment out PythonHandler mod_python.publisher, it returns the Python script un-parsed.

How do I use Python on a virtual host?

EDIT. If testpython.py consists of script print( 'xxxx' ), I get the 404 error. If it consists of the following, it returns Test successful.

def index(req):
return "Test successful";


Both produce the following notice in /var/log/httpd/error_log:

[Mon Dec 07 07:03:14 2015] [notice] mod_python (pid=16441, interpreter='example.com'): Importing module '/var/www/python/html/testpython.py'

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Mendez628

2 Comments

Sorted by latest first Latest Oldest Best

 

@Annie201

I didn't use mod_python yet, but it seems to me that the script is expected to return (rather than print) the text to be served, and to contain an index function to accomplish this.

If you don't define the index function, mod_python won't know what to do about your module.

10% popularity Vote Up Vote Down


 

@Steve110

A couple things to check:


The script is executable
var-www has permission to access it


Check the permissions on the script. They could be set such that only root can read it.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme