Your skill will accomplish
what the force of many cannot
Perl on Mac OS X ! (and Apache)by fpi (Monk)
|on Mar 26, 2001 at 16:01 UTC||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:
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...