Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.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 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'
share|improve this question

A couple things to check:

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

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.