Hello! So I decided I wanted to try some CGI... and it's not working out well at the moment, any help would be greatly appreciated!

So essentially in my 000-default virtual host config file I have this:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /home/apott/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /home/apott/www>
                Options +ExecCGI Indexes FollowSymLinks Includes
                AddHandler cgi-script .cgi .d .py
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/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
</VirtualHost>

The CGI scripts I'm trying to use are kept in the specified DocumentRoot

So currently whenever I go to a CGI script I just get a 403 forbidden error, but if I put the +ExecCGI here: Options +ExecCGI Indexes FollowSymLinks Includes at the end of the line I get a 500 server error, if that means anything to anyone.

Any help will help tons! Thanks in advance.

Hi, the config seems fine, so it can be a permission issue or the mime-type (each CGI needs the mime-type declaration at the top of the script), check this link for more information: http://httpd.apache.org/docs/2.2/howto/cgi.html#writing

Also, check Apache error logs to get more details about the issue. Hope it helps.

I have declared the MIME type as well as changing permissions of the files (I have tried chmod a+x and chmod +x).
This was in the error log, not sure if it's of any signifigance:

[Thu Jul 18 18:52:00 2013] [error] [client 127.0.0.1] Options ExecCGI is off in this directory: /home/apott/www/D/test.py, referer: http://localhost/D/

If I change +ExecCGI to ExecCGI it gives a 500 internal server error and the error.log says:

[Thu Jul 18 19:20:25 2013] [error] [client 127.0.0.1] (13)Permission denied: exec of '/home/apott/www/D/test.py' failed, referer: http://localhost/D/
[Thu Jul 18 19:20:25 2013] [error] [client 127.0.0.1] Premature end of script headers: test.py, referer: http://localhost/D/

EDIT:
I got it working with Python now, I can figure the rest out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.