Apache2.4.7 on Ubuntu 14.04 won't execute Python cgi file. The site displays python code instead

Description of problem:

When I load 127.0.0.1/cgi-bin/test.cgi in my browser my test.cgi is treated like a text file instead of a python file.

Ruling out the possibility of the error being related to the python code:

  • I can't get an intentional 500 error, no matter what I do to the python code.

  • And I've made the cgi file executable via sudo chmod +x.

  • I've done this before in previous versions of Ubuntu with out issue.

Theory:

I believe the problem lies in my configuration. Below is my configuration of two files, apache2.conf and 000-default.

I've been pasting different things in to make my configuration files work, every chance I get. This is just a snapshot of what these two files look like at the time of writing this.

Thank you, in advance!

/etc/apache2/apache2.conf:

Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf

<Directory /home/isaac/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

AccessFileName .htaccess

<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent


IncludeOptional conf-enabled/*.conf


IncludeOptional sites-enabled/*.conf

/etc/apache2/sites-available/000-default:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /home/isaac/www
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

ScriptAlias /cgi-bin/ /home/isaac/www/cgi-bin/
    <Directory "/home/isaac/www/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
        AddHandler cgi-script .py
        AddHandler default-handler .html .htm
    </Directory>

The first problem would be because the CGI module hasn't been enabled, so Apache isn't processing anything as CGI. ENable it:

sudo a2enmod cgi

In Apache2.4, the configuration was cleaned up considerably, and things in the default site definition have been moved to configuration files in conf-available. Among other things, this also includes the CGI-related configuration lines seen in the default site of older versions. These have been moved to /etc/apache2/conf-available/serve-cgi-bin.conf, which contains:

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

This causes the second problem. Either modify that file, or disable that configuration:

sudo a2disconf serve-cgi-bin