Apache, Perl, CGI scripts

brutfood

Registered
I want to develop CGI scripts using Perl running under Mac OS X. I've written some stuff, that I'm able to run under from the command line interface, but now I want to trigger them from Flash or HTML.

I assume I need to run Apache locally in order to do this. (correct this assumption if wrong). There's no need to connect to the outside world - so how do I configure and run apache, so I can just use it to test and develop my scripts?

Or am I barking up the wrong tree?

Daniel
 
Just click "Start web sharing"
Put your cgi-scrips on Library/WebServer/CGI-Executables. And be shure to make them... executable.
 
Thanks for that - but this is all new to me and I probably need to be guided a step at a time. (sorry)

This is as far as I got:-

I tried enabling WEB sharing, later, I also tried starting up apache:-

sudo apachectl start

I put the following file in /Library/WebServer/CGI-Executables, and called it mytest.cgi


#!/usr/local/bin/perl

use CGI ‘:standard’, ‘-debug’;
open(OUTPUT, “>>results.txt”) or die “Can’t write to results.txt: $!”;
print OUTPUT “Here is a file to prove this script has run\n”;


When it is run, this simple Perl program just creates a file called results.txt. (I tested it from the command line, and it works). Then I created some Flash actionscript with the following command:-

getURL(“http://127.0.0.1/cgi-bin/mytest.cgi”, _self, “GET”);


When I tried it out, I got a ‘500 Internal Server Error’ page - which suggests I’m almost there. So, how do I make it work properly?

Daniel
 
"I tried enabling WEB sharing, later, I also tried starting up apache:-
sudo apachectl start"

This is the same thing, pressing "Start" web sharing starts Apache. You don't have to start it from the prompt.

Have you made the cgi executable with:
sudo chmod a+x mytest.cgi

This has to be done with printenv and test-cgi , already present in the cgi folder, in order to make them work.
 
Actually, I left nothing to chance and did:-

sudo chmod 777 mytest.cgi

This isn't the problem. The error I got mentioned a log file. Do you know where this would be?

Daniel
 
It COULD be something with the write permission. Try to include a path in the filename results.txt to a path with a+w permissins
 
First: I think you have apache going, but jus to make sure, does test-cgi and printenv work? http://localhost/cgi-bin/test-cgi and http://localhost/cgi-bin/printenv ... there might be some config issues, doubtful if you have the stock apache running.

If apache is not starting, try starting it from command line and see what breaks. If apache is serving correctly (which it looks like since you are geting a 500) move on down below ->

Second: Why are you using /usr/local/bin/perl? Did you install a newer version of perl? Try it with the shipping perl at /usr/bin/perl ... shouldn't matter, but you should cover all the bases.

Third: The 500 error is internal error, make sure that www has write permissions at the root of /Library/WebServer/CGI-Executables.

Finally: check the log file /private/var/log/httpd ... there should be a file called error_log there. Please post the relevant error lines.

Good Luck,
__nether
 
In your /var/log/httpd/error_log you get:
Cant write to results.txt: Permission denied at /Library/WebServer/CGI-Executables/mytest.cgi line 4

So its a write permission thing.
If you try /tmp/results.txt as the output file it works, but you still get a error 500 in the browser, but thats because you don't generate any valid html in your cgi.

and the first line should be:
#!/usr/bin/perl
 
It works! The world is my oyster.

And I know where to find my error diagnostics now.

Thanks guys - you cracked it while I was asleep here on the other side of the world.

Daniel :)
 
Back
Top