Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

How do I access cgi scripts from the browser if the CGI-Executables directory is above the www-root folder? I don't want to use something like ../. I tried browsing to localhost/cgi-bin/ but it gave an error. It said permission denied.

How do I configure these settings? Also can /~user-name directory aliases run cgi-scripts?

share|improve this question

2 Answers 2

If you have a look at the main Apache2 config file, /etc/apache2/httpd.conf you will see that there are two things that have to be done to allow /Library/WebServer/CGI-Executables contain the cgi files.

First, since it isn't covered by the permissions for the document directory next to it, it will need a "Directory" block to define the permissions for all the files and directories under it. In the case of this directory it allows absolutely nothing to happen. This is why when you pointed your browser at the directory it said permissions denied. Don't worry, the second thing allows cgi files in the directory to be run.

Second, it needs a "ScriptAlias" command that tells the server what URL will be used to point to it so that the server finds the files and allows them to be run.

ScriptAliasMatch ^/cgi-bin/((?!(?i:webobjects)).*$) \
"/Library/WebServer/CGI-Executables/$1"

This basically says "after you remove the hostname then any URL that starts "/cgi-bin/" and continues with a piece of text followed by a period followed by another piece of text points to a file with a name matching the last bit in the directory ""/Library/WebServer/CGI-Executables/$1"

If you want to place CGI files in one of your user directories then you will need to make some changes to a different config file. You will find the config file for user shares in /etc/apache2/users with a config file for each user. Here is an example:

<Directory "/Users/jessica/Sites/">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

To this you will have to add either "ExecCGI" to the "Options" line so that you can have CGI files anywhere in your Sites directory or under or add a new Directory block for your CGI folder. It would look like this :-

<Directory "/Users/jessica/Sites/CGI">
    Options ExecCGI
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

Since this is under our DocumentRoot we don't need to use the ScriptAliasMatch.

(The second option is the more secure.)

share|improve this answer

I usually hate doing this but with some experimenting I figured out how to solve the issue.

  1. Add a script to the CGI-Executables/ folder, and set it's permission to 755 (chmod 755 ./file-name.

  2. If you want to change this configuration, $cd /etc/apache2/ and edit the httpd.conf file. I was able to confirm that this is the correct location managing the setting, with this snippit from the file.

ScriptAliasMatch ^/cgi-bin/((?!(?i:webobjects)).*$) "/Library/WebServer/CGI-Executables/$1"

I'm not sure exactly what it does, but I can be pretty sure from the characters that it creates the cgi-bin as an alias to CGI-Executables. So to modify this as being the folder, simply change this setting here to a different location.

I'm still not sure about setting up a cgi-bin for a ~/user-name directory if anyone can help with that

share|improve this answer
    
For a truly secure web service change the owner of your cgi files to _www and change the permissions to 700. (Then your entire document tree should also be owned the same and have permissions of 600.) –  Tony Williams Jan 26 at 7:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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