Why doesn't CGI ever work!?

Hi,
I can never get CGI scripts to work on OS X Server.
I have the cgi module enabled in Server Admin, and I chmod 777 the script, and I put it in /Library/WebServer/CGI-Executables/
and then go to domain.com/cgi-bin/test.cgi
and I always get a Forbidden or Internal Server Error page

Any recommendations?

Posted on Apr 14, 2007 2:54 PM

Reply
5 replies

Apr 14, 2007 4:12 PM in response to J R3

>Any recommendations?

Read the logs.

Typically the logs will give you some idea of what happened. If you're blindly copying scripts from other systems the most common fault is an incorrect path to the interpreter (e.g. #!/bin/perl instead of #!/usr/bin/perl which is what's appropriate for Mac OS X.

Either way, the logs are the first place to check. /var/log/httpd

Apr 14, 2007 4:34 PM in response to Camelot

I took a look at the logs,
I have a few questions:
1) why does it give a forbidden error when I try to view an html page that resides in cgi-bin?
here is the error:
[Sat Apr 14 19:34:08 2007] [error] [client 10.1.0.100] file permissions deny server execution: /Library/WebServer/CGI-Executables/Installer/index.html

but the file was chmoded to 777.

2) how do I fix this error (for a cgi file that's not in cgi-bin)?:
Options ExecCGI is off in this directory:

Apr 14, 2007 8:37 PM in response to J R3

>1) why does it give a forbidden error when I try to view an html page that resides in cgi-bin?

Because files in cgi-bin are expected to be executed, not viewed. Especially if you've set the execute bit - you're telling apache to execute a .html file which isn't going to work.

In addition to that, you need to check the permissions on every directory in the path, including the /Installer directory. This needs to be at least 555 so that Apache can see the files in it.

>2) how do I fix this error (for a cgi file that's not in cgi-bin)?

Executing cgi's outside of the cgi-bin directory/path is not recommended. It opens potential security issues, especially if you allow other users to create web content.

However, if you really want to, you'll need to add an Options +ExecCGI statement to your httpd.conf, like:

<pre class=command><Directory /Library/WebServer/Documents/InsecureCGI>
Options +ExecCGI
</Directory></pre>

Now any URL of the form http://your.server.net/InsecureCGI will be executed as a CGI.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Why doesn't CGI ever work!?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.