Perl and PHP

gruven28

Registered
I just installed OSX and updated to 10.1. I started Apache and everything works great. Tried the test.cgi on Apple's page (http://www.apple.com/creative/webpro/technology/terminal/index2.html), still good - worked fine. Created a very simple perl script, doesn't work:

#!/usr/bin/perl

print "hello";

Dumped the file 'test.pl' into the CGI_Executables folder, chmod 755 test.pl. Any ideas on why it's not working?

Same goes for php - created simple file that has phpinfo command, dumped into the Documents folder under Webserver...Uncommented lines in Apache httpd.conf, restarted apache, and IE prompts me with the mime type problem of "don't know what to do with this file...Download it?"

Any ideas would be greatly appreciated. Thanks,
 
Did you uncomment
AddHandler cgi-script .cgi
and
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
in httpd.conf?
 
Yup, sure did. Used BBEdit (6.5) and saved over the original http.conf. Uncommented those lines, restarted using the "websharing" in Sys prefs, no luck.

The perl file gives me "Internal Server Error" but I believe that the file's syntax is fine.

which perl at the terminal yields:

/usr/bin/perl

So that should be set and ready, yet doesn't work.

PHP gives me "Unhandled File Type" from IE. Meaning, the mime type is not configured?

Is there somewhere else that I need to configure the mime types for apache or something?
 
say. If you check the logs, it will tell you what went wrong. I haven't fired up the webserver on my mac yet, but I use apache dailly on my FreeBSD box and the logs will tell you what went wrong in the execution of your perl script. Make sure that you are checking the error logs.

Oh and BTW, the addhander cgi-script .cgi doesn't control whether or not a cgi script will run, what it does is allow any cgi-script that is suffixed with .cgi to run in the directory that happens to be in... thus not requiring it to be placed in a special cgi-bin directory before allowing execution. If you have a .pl cgi script and its in the designated cgi-bin directory, and the permissions are set for execution by others ie chmod 755 test.pl it should run if there are no coding errors. Make certain that your httpd.conf file has that cgi-bin directory specifically called out like so

ScriptAlias /CGI_Executables/ "/usr/local/www/CGI_Executables/"

make sure the paths match your installation, but if you don't have something in your .conf file like the above example, you can't run cgi scripts until you add it, or uncomment it.


BSDimwit
 
I get the same error you got when I follow exactly what you did. I get the following from my error_log:

[Wed Apr 10 15:51:07 2002] [error] [client xxx.xxx.xxx.xxx] malformed header from script. Bad header=Hello, World!: /Library/WebServer/CGI-Executables/hello.cgi

I know that cgi and perl are configured correctly. I can run a .pl file from my webserver and I can run the default test-cgi file supplied in OSX. But when I create a simple "Hello, World!" Perl script with either a .cgi or .pl ending, I get the Internal Server Error. I unfortunately do not know enough about apache or perl to figure this out. I have no problems with php files.

SA:)
 
After reading the default cgi file printenv that comes with OSX, I guess I need the cgi script to print the html code instead of just a perl file print? I'll give this a try and see how it works.

Dohh!
SA:p
 
Hope this isn't a copyright infringement.
I replaced:
#!/usr/bin/perl
print "Hello, World!\n";

With the following:
#!/usr/bin/perl -T
##
# Show CGI Process Environment
##
# This perl program shows you how to access the process environment
# for CGI programs on your web server.
# It is also a useful debugging tool, as it shows you all of the
# available environment variables.
##

exit unless ($ENV{'REQUEST_METHOD'} eq "GET");

# CGI programs must print their own HTTP response headers
print "Content-type: text/html\n\n";

# Declare the SGML application as HTML
print "<!doctype html public \"-//W3C/DTD HTML 4.0/EN\">\n";

# Begin HTML
print "<html>\n";

# A minimal document must include a header region with a title
print "<head>\n".
"<title>Hello World!</title>\n".
"</head>\n\n";
# Start document body
print "<body>Hello, World!\n\n";
# End document body
print "</body>\n";

# End HTML
print "</html>\n";

exit 0;
I borrowed most of the code from the default printenv cgi file located in the cgi-bin in OSX.

Now I feel foolish.
Doohh!!

SA
 
While I was concentrating on making sure the cgi script could be executed, I forgot to mention that the print "Hello World\n"; program wouldn't work when coming from a Webserver...

The key is to output HTML and you did so with your

print "Content-type: text/html\n\n";

<INSERT HTML TAGS here>

This tells apache what type of content it is about to serve up.

Glad to see you got it working.

BSDimwit
 
Back
Top