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 http://python.org/ftp/python/3.3.5/Python-3.3.5.tar.xztar xf Python-3.3.5.tar.xzcd 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 http://example.com/testphp.php
, it is parsed as PHP, however, if I access http://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'