Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Perl on Mac OS X ! (and Apache)

by fpi (Monk)
on Mar 26, 2001 at 16:01 UTC ( #67177=perlmeditation: print w/ replies, xml ) Need Help??

Macintosh OS X (10.0) was just publicly released this past weekend. Now before you start to roast me with this post, read it first, because it is quite relevant to the Perl community who are interested. I am posting what I have discovered regarding Perl on OS X, both with this release and with what I learned while testing the OS X beta.This Perl info is not yet documented, nor announced at all, and almost never discussed in the Mac discussion groups:

For those of you who don't know yet, OS X is UNIX-based. Specifically, it is based on BSD, with something called Darwin, and on top of it is the Aqua interface based on PDF technology. Yes, it is a Mac with a UNIX command prompt, Apache webserver, FTP server, remote telnet access, man pages, permissions and groups, and ..... Perl! What this means is no more reliance on MacPerl or WebStar. But it's NOT Linux, so investigating more about the Perl setup is appropriate.

Ok, first thing is first:
CommandResult
which perl/usr/bin/perl
perl -vThis is perl, v5.6.0 built for darwin...

And when I typed perl -MCPAN -e shell,cpan popped up! (pardon my enthusiasm, but this is exciting because I have been a Mac user for years). But I didn't try to load a module yet because I have to do some more investigating of the directory structure before I can even configure CPAN. Using Sherlock, I found the Perl modules in /System/Library/Perl. Looks as expected, with the addition of a darwin directory containing another set of standard modules.

I have been looking forward to OS X primarily because of Perl and Apache, so I could do Perl web development and testing on a Mac. So naturally I have to check out Apache. This gets interesting...

Most significantly, you do NOT have root access...
You can't start root processes from the command line, edit root config files, or change root ownership or permissions. So to turn Apache on and off, you have to go to control panel, or specifically the "Sharing panel" in the System Preferences (this is also where you turn on the FTP server and remote telnet). The button is "Web Sharing On" (but I've seen it change between reboots - a bug). This should make it easy to restart Apache after making changes to httpd.conf (or so I thought).

So then I find httpd.conf at /private/etc/httpd/httpd.conf. I vi the file and see that the Document Root is set at /Library/Webserver/Documents . The script alias for */cgi-bin/ is set to /Library/Webserver/CGI-Executables. So far, nothing unusual except the path names, right? But get this - in the settings for the CGI-Executables directory, "ExecCGI" is NOT specified in the "Options" (this is opposite the usual default Apache configuration). And like the usual Apache default, the "AddHandler cgi-script .cgi" line is commented out. So what does all this mean? The default configuration does not allow you to execute Perl script by web.

So just edit the httpd.conf file, right? I can't - only root can edit it, and the installation process doesn't let anyone be root. So unless someone knows the password posted somewhere, I don't have root access. So basically, OS X gives you a cgi-bin, but doesn't allow you to use it! i.e. you can't use Perl for the web on OS X.

(Update: for the solution, follow blueflashlight's below, but you can read my solution because it is interesting, and could possible come in handy some day:)
BUT - there is a solution. And the solution works. When you install OS X, put it on it's own partion, separate from an OS 9 partition. And make sure you format the OS X partion as Mac Extended and NOT Unix. This is VERY important, not only because it seemed to be much more sluggish as a Unix partition, but because if OS X is put on a Mac Extended partition, it can BE SEEN by the OS 9 partition.

Therefore, just boot into OS 9, access your OS X partition, find the httpd.conf file and edit it with no problem. Permissions apparently don't apply when you are accessing from OS 9. Also, you have to boot into OS9... this trick will NOT work by using the OSX-OS9 Classic mode. Then boot back into OS X, chmod 755 your script, and it will work.


Ok, having said all this, don't do it unless you are used to editing the Apache configuration file. Also, the /private directory will not be visible thru the Finder windows of OS X or OS 9 - you have to use the Terminal in OS X or an application's Open dialog box in OS 9. And lastly, but also VERY important - Any configuration files or Perl scripts MUST be saved with UNIX line breaks! This is different from Mac line breaks. This will drive you nuts if you don't catch it, and the included editors will save with Mac line breaks. I use BBedit, which allows you to save with Mac, UNIX, or Win line breaks. Added: flay suggested I add further explanation: "Mac (OS9) linebreaks are carriage returns (CR), Unix linebreaks are linefeeds (LF), and Windows linebreaks are both (CR+LF)". OS X (unix) cannot read a perl file saved as a OS 9 (mac) text file.

The apache error log is at /private/var/log/httpd/error_log.

Now there are plenty more questions I have about the Perl, such as can I install a module correctly, will a CGI.pm upload work? Or DBI, DBD, and...GD (probably not)? I can't be the only one here interested in OS X....the animated, transparent, shadowed GUI interface is actually the most advanced of all OS's, although better be prepared for some heavy memory and CPU requirements. So if any of you experiment with the Perl on OS X, please post your discoveries. Or if you are interested, but don't have access to an OS X machine, post what you want me to investigate about the Perl (and how to investigate), and I will try to figure it out....

Added: if you go to the Apple menu and select "Get Mac OS X Software...", you will be taken to a website where you can find Pepper, an OSX (Cocoa) editor that has Perl syntax highlighting, provides a popup list of your subroutines in your script, and saves in Unix format....I was happy to find this because BBedit hasn't yet announced their OSX version...

Comment on Perl on Mac OS X ! (and Apache)
Select or Download Code
Perl/Tk on OS X
by jepri (Parson) on Mar 26, 2001 at 20:10 UTC
    I'd really like to hear something about Perl/Tk on OS X. Mainly because I'd love to be able to advertise my code as "running on Mac and IBM without any changes needed". Although I guess that won't catch x86 Solaris. But I don't think too many people would spot that exception.

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.

Re: Perl on Mac OS X ! (and Apache)
by blueflashlight (Pilgrim) on Mar 26, 2001 at 20:41 UTC
    this has been posted in a million places, but here is the million-and-first. To enable root in Mac OS X, open a shell as your normal administratior account, and type

    sudo passwd root

    enter your adminstrator password, and then enter the password that you want for root. and now you have root.

    of course, you don't need root active, as you can just type ...

    sudo /what/ever/command/you/want

    and it will run as root.

    sorry for getting so off-topic, but don't want people to think that Mac OS X is a half-baked unix. It really is a fully-baked unix.

    --Sandy
      It's not off-topic - I knew someone here would know a better way. Thanks, blueflashlight. I'm surprised I never came across this info anywhere else.Probably because the mac discussion groups are cluttered with topics in which I have no remote interest.

      You're right, it is really a fully-baked unix, and my satisfaction with OS X just increased significantly. Especially after my first install, which was so sluggish I was ready to write off Apple forever....the only thing differently I did was to format the partition as "Unix" (sluggish)instead of "Mac extended" (works fine)....

      Now my dilemma is which OS/computer to choose as my primary development machine - the Mac or the Linux...

      My apologies to jepri above. I don't work with Perl/Tk normally, so I'll leave it for someone else to test.
Re: Perl on Mac OS X ! (and Apache)
by merlyn (Sage) on Mar 27, 2001 at 17:05 UTC
    I don't know if it's been said anywhere in this thread, but I successfully built expat, and therefore XML::Parser, and HTML::Parser, and the Apache is mod_perl enabled, but you have to edit the config file to enable it. It's a slightly older mod_perl, but all the core Apache::* modules are installed already too (which is what tipped me off to looking for the modperl.so file).

    -- Randal L. Schwartz, Perl hacker

Re: Perl on Mac OS X ! (and Apache)
by Anonymous Monk on Apr 05, 2001 at 06:46 UTC
    just a small comment on Mac OSX .. glad the NeXT software didn't go to waste. :p But, I think it is pretty cool that perl comes bundled with it.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://67177]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2014-10-02 08:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (52 votes), past polls