# [sf-perl] perl on a mac

Darin Fisher darin_fisher at yahoo.com
Mon Nov 17 18:34:47 PST 2008

Shoot, I forgot about adding a handler (a little too used to mod_perl I guess).

Thank you Lara for the great detail for this OS.

-Darin

Not a shred of evidence exists in favor of the idea that life is serious.
- Brendan Gill

________________________________
From: Lara Ortiz de Montellano <lara.ortiz.de.montellano at comcast.net>
To: sanfrancisco-pm at pm.org
Sent: Monday, November 17, 2008 2:21:27 PM
Subject: Re: [sf-perl] perl on a mac

1. Re: perl on a mac (Walt Sanders)

> Terminal won't run it of course, it just spits that code back at me.   But, if I try to run it in a browser, of try to preview it in an  editor, it still spits code back at me.  This is any program that runs  perfectly fine when I upload it to any one of my ISP servers.  I can  just download any working .cgi or .pl from one of my websites and it  won't run on my machine.
>

To expand a bit on Darin's instructions in a Mac specific context (and this is going to be long and possibly something you already know)...

It sounds like you're seeing the correct, but raw HTML when you expect to see interpreted HTML if you run the code on the command line, and raw perl code if you open it in the browser?

If so, the deal is that the terminal/command line executes the Perl but does not render HTML.   This is correct and expected behaviour.   You should see the same thing if you run the script on Windows under
Start->
Run->
cmd [OK]
c:> perl c:\some\path\to\your\script.pl

Opening the perl script directly in the browser will get you the raw Perl code because the browser itself cannot execute the Perl code, it only understands the HTML (and figures anything else is plain text).

So... you need to execute the Perl by having your browser ask a web server to execute the script and return the (HTML) contents to the browser.

To do this:

1) Configure your web server to allow CGI scripts:

a) In Terminal, use the whoami command to see what the Mac thinks your user id is.

b) Under /etc/httpd/users (under 10.4) or /etc/apache2/users/ (10.5) create a file called username.conf where "username" is your userid name on the mac.

AllowOverride All
</Directory>

set the permissions on the file:

sudo chgrp www .htaccess
chmod 750 .htaccess

and in the file, add the text:

Options ExecCGI

e) Under the apple menu, choose System Preferences and click on Sharing, then turn off (by unticking) Personal Web Sharing, then turn it back on (by ticking Personal Web Sharing).

2) Set your script up to be accessible to the web server

a) In Terminal, run     which perl     to see which Perl you're using, and make a note of the path (usually /usr/bin/perl)

b) Add a shebang line to your perl script to tell the web server how to execute your script, using the path  you got in 2a:

#!/usr/bin/perl

d) Set the file permissions to allow world execute on the script:

3) View the file in your browser at

Do you see what you were expecting?
If so, you'll want to read up a bit on Apache  CGI  and you may also want to tweak the Apache and script file permissions to make it a little more secure.

-Lara O.

_______________________________________________
SanFrancisco-pm mailing list
SanFrancisco-pm at pm.org
http://mail.pm.org/mailman/listinfo/sanfrancisco-pm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20081117/e2daf62e/attachment.html>