2

I am trying to run CGI on FreeBSD 9.2.

  1. I installed Apache 2.4 (pkg install apache24)
  2. Configured it to load CGI module.
  3. Also, I did chmod a+x on files in cgi-bin directory.

And when I connect to the server to a test CGI script, the server printed this error message.

AH01215: (13)Permission denied: exec of '/usr/local/www/apache24/cgi-bin/test-cgi' failed
End of script output before headers: test-cgi

What's wrong and how to fix this problem?

2 Answers 2

1

You also need "others read" permissions:

> ls -l test-cgi 
-r-x-----x  1 root  wheel  779 Dec 11  2004 test-cgi
> curl -s -w "%{http_code}\n" -o /dev/null http://localhost:8080/cgi-bin/test-cgi
500
> chmod o+r test-cgi ; ls -l test-cgi 
-r-x---r-x  1 root  wheel  779 Dec 11  2004 test-cgi
> curl -s -w "%{http_code}\n" -o /dev/null http://localhost:8080/cgi-bin/test-cgi
200
0

The problem is shell. Apache 4.2's test CGI scripts are written for bash, and FreeBSD comes with default shell csh. The scripts are not compatible with csh, so it fails, and Apache spits an error.

To fix this, (1) install bash, and (2) add shebang to specify bash location.

Because FreeBSD userland is explicitly separated from base, installed bash will be placed in /usr/local/bin rather than /bin. So add a shebang like this.

#!/usr/local/bin

And then, the script will work well.

1
  • 2
    I'm not sure this is quite correct. It's been a long time since I've run Apache but I recall the same error the first time I tried it and switching shells, in this way, was not the solution. If you notice the error says, "Permission denied..." which is not an error from using the wrong shell and installing a package should have resolved that if the shell was the problem.
    – Rob
    Commented Apr 15, 2015 at 12:21

You must log in to answer this question.

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