# Problems running CGI-scripts in Apache.



## Claruz (Mar 21, 2003)

I am having some problems with my built in Apache installation. I am running Mac OS X Client, not server, version 10.2. Here is the output from httpd -version:

Server version: Apache/1.3.26 (Darwin)
Server built:   07/27/02 14:29:15

I am trying to run cgi-scripts. I found the main "cgi-bin" folder to be /Library/WebServer/CGI-Executables. So that is where the cgi scripts are being run from. I keep getting "500 Internal Server Error". I have made sure that the permission is correct for the script. I also checked the #!/usr/bin/perl header of the script, and it appears to be correct. I have read all that I can find in the Apache manual about this and I can't see what I am doing wrong. Here is what the error log says about it :

[Fri Mar 21 12:54:37 2003] [error] (2)No such file or directory: exec of /Library/WebServer/CGI-Executables/perl_test.cgi failed
[Fri Mar 21 12:54:37 2003] [error] [client 127.0.0.1] Premature end of script headers: /Library/WebServer/CGI-Executables/perl_test.cgi

Running the script from the terminal work fine, even when I use "sudo -u www perl <script>" to try and emulate the permissions that the script would have when being run from the webserver. The script I am trying to run is part of the ikonboard 3.11 installation and is designed to test your webserver to see if everything will run fine. The script should be fine, all it does is check the Perl version, CGI version, sendmail path and some other simple stuff. I can post the script here if you want. Is there any other setup I need to do to run CGI scripts? If not, then what could be wrong?

Thanks for any help you can give.


----------



## Darkshadow (Mar 21, 2003)

Small thing - does the script have the executable bit set?  Probably  does, but if it doesn't, this is the sort of thing that happens, so I thought I'd ask.


----------



## Claruz (Mar 21, 2003)

If you mean the permission for executable, then yes, it is set. The script has been chmod 755 so it is executable and readable by everyone, and writable by the owner. If it wasn't the permission thing you meant then please explain what, I might have missed it.

Thanks


----------



## toast (Mar 21, 2003)

Try typing http://yourdomainhere.org*/cgi-bin/*perl_test.cgi.
If it doesn't work, CHMOD to 777.
If it still doesn't work, post again .


----------



## Claruz (Mar 23, 2003)

Since my machine doesn't have a domain name I am using this address : http://127.0.0.1/cgi-bin/perl_test.cgi. I also tried doing chmod 777 on the file, but no luck.

I'm not very bothered anymore, but it is a bit strange. I have found phpBB and I prefer it too ikonboard.

Thanks


----------



## Darkshadow (Mar 23, 2003)

You could use *localhost* rather than 127.0.0.1 and it would work as well.  And yes, the permission for execution was what I was talking about.


----------



## TommyWillB (Mar 23, 2003)

Are you sure the sh'bang is right (#!/usr/bin/perl)?

Did you remember to print "Content-Type: text/html\n\n"; before outputing anything else?

Have you changed httpd.conf? Does it still include these lines without a # in front of them: 
	
	



```
AddHandler cgi-script .cgi
.
.
.
ScriptAlias /cgi-bin/ "/Library/WebServer/CGI-Executables/"
```

What does the script do when you run it from the command line:





> bash-2.05a$ perl  /Library/WebServer/CGI-Executables/test.cgi
> Content-Type: text/html
> 
> Here's an example of a .cgi that proves that .cgi's work on your website!
> ...


----------



## TommyWillB (Mar 23, 2003)




----------



## Claruz (Mar 24, 2003)

As I said earlier the #!/usr/bin/perl is correct, and the script runs fine from the terminal. The script does print the headers before anything else, I didn't write it. The http.conf file is fine, I just checked it. Don't worry....unless I decide to use CGI again at some point you won't hear from me 

Thanks


----------



## kilowatt (Sep 23, 2003)

add -wT to the perl

eg:
#!/usr/bin/perl -wT


----------

