7

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>
| improve this question | | | | |
  • 2
    Did you enable the CGI module? sudo a2enmod cgi? – muru Nov 9 '14 at 2:12
  • Done. Finally, I'm getting an error. "The ScriptAlias directive in /etc/apache2/sites-enabled/000-default.conf at line 9 will probably never match because it overlaps an earlier ScriptAlias." I don't get it, since there is no earlier alias. – Isaac Nov 9 '14 at 2:21
  • 1
    Since you're using Apache 2.4, see if you have this file: /etc/apache2/conf-enabled/serve-cgi-bin.conf. – muru Nov 9 '14 at 2:30
  • Yes I do have that file! – Isaac Nov 9 '14 at 2:37
  • YES THAT DID IT!! That was the file I needed to add the text to! It works now! You you mind answering this question? I'll mark this as solved! – Isaac Nov 9 '14 at 2:40
9

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
| improve this answer | | | | |
  • 3
    Thank you! I pasted my code into /etc/apache2/conf-enabled/serve-cgi-bin.conf – Isaac Nov 9 '14 at 2:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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