0

I am running Apache/2.4.10 (Ubuntu) and I was trying to run CGI scripts with the following configurations.

/etc/apache2/apache2.conf

With the following

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 />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/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

###################################################################
#########     Adding capaility to run CGI-scripts #################
ServerName localhost
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
Options +ExecCGI
AddHandler cgi-script .cgi .pl .py

And the /etc/apache2/conf-available/serve-cgi-bin.conf

<IfModule mod_alias.c>
    <IfModule mod_cgi.c>
        Define ENABLE_USR_LIB_CGI_BIN
    </IfModule>

    <IfModule mod_cgid.c>
        Define ENABLE_USR_LIB_CGI_BIN
    </IfModule>

    <IfDefine ENABLE_USR_LIB_CGI_BIN>
        #ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        #<Directory "/usr/lib/cgi-bin">
        #   AllowOverride None
        #   Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        #   Require all granted
        #</Directory>

        ## cgi-bin config
        ScriptAlias /cgi-bin/ /var/www/cgi-bin/
            <Directory "/var/www/cgi-bin/">
                AllowOverride None
                Options +ExecCGI 
            </Directory>

    </IfDefine>
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

I have my cgi-script in the directory /var/www/cgi-bin

with the contents in hello.py and made it executable.

#!/usr/bin/env python

import cgitb
    cgitb.enable()    print("Content-Type: text/html;charset=utf-8")

print "Content-type:text/html\r\n\r\n"
print '<html>'
print '<head>'
print '<title>Hello Word - First CGI Program</title>'
print '</head>'
print '<body>'
print '<h2>Hello Word! This is my first CGI program</h2>'
print '</body>'
print '</html>'

I also did sudo a2enmod cgi as suggested here Apache2.4.7 on Ubuntu 14.04 won't execute Python cgi file. The site displays python code instead

When I try to run the script by going to http://localhost/cgi-bin/hello.py I am getting a 500 Internal Server error.

Any help would be greatly appreciated! Thanks

1 Answer 1

0

Saw the error logs in /var/log/apache2/error.log and saw that there is an indentation error because of the cgitb.enable().

Corrected the indentation and now its running fine.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .