0

I'm at my wits end trying to figure out why I can't run .py files outside of my cgi-bin directory. I installed mod_python, and was able to successfully run .py files after setting up my sites-available/default file as follows in Apache2:

<VirtualHost *:80>
ServerAdmin webmaster@localhost

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

ScriptAlias /cgi-bin/ /var/www/cgi-bin/
<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

The code above only allows me to run .py files inside the cgi-bin.

From what I understand, I don't want to use CGI to run python, because it's not efficient. I'm trying to follow this tutorial, and in doing so, I have modified my sites-available/default file to the following:

<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
          AddHandler mod_python .py
          PythonHandler mod_python.publisher
          PythonDebug On
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

After modifying my sites-available/default to the code above, every .py file I try to run from a browser returns a 404 error. Permissions are 755 for all .py files I have found.

Any help at all would be greatly appreciated.

  • 1
    Showing a particular request URL and the errorlog entry it generates would be helpful – covener Feb 15 '14 at 23:39
  • 2
    Step 1: [Stop using mod_python.](http://blog.dscpl.com.au/2010/06/modpython-project-is-now-officially.html) Step 2: Get mod_wsgi. – Ignacio Vazquez-Abrams Feb 15 '14 at 23:41
  • @covener Request URL: ipaddress/test.py Error: [Sat Feb 15 13:15:38 2014] [notice] mod_python (pid=2698, interpreter='vps.server.com'): Importing module '/var/www/test.py' [Sat Feb 15 13:15:38 2014] [error] [client 50.162.38.135] File does not exist: /var/www/favicon.ico [Sat Feb 15 13:15:38 2014] [error] [client 50.162.38.135] File does not exist: /var/www/favicon.ico – user3314660 Feb 16 '14 at 00:16
  • Doesn't look like a 404 was generated for /test.py from httpd. Maybe mod_python did that and didn't log a message. – covener Feb 16 '14 at 12:48

0 Answers0