Mac OS X Server
Mac OS X Server
mod_perl on Snow Leopard Server
Saturday, 16 January 2010
It’s been about four months since I first installed Snow Leopard Server, all in all I’m quite impressed. One thing that I found a great improvement over Leopard Server was that the mod_perl module was compiled properly to run on the server with no further changes required.
Enabling mod_perl
1.Click on the Web service
2.Click on Settings
3.Open Server Admin and connect to the Snow Leopard Server
4.Click on the modules tab
5.Click the + at the bottom of the module list and enter the following
•Module Name: perl_module
•Enabled [Checked]
•Module Path: libexec/apache2/mod_perl.so
6.Click OK
7.Click Save

mod_perl is now enabled and you can add your desired configuration to the site configuration files.
Using mod_perl
In /etc/apache2/sites you’ll find your website configuration files.
Edit the appropriate file for the site you want to enable mod_perl for and enter your configuration which will be along the lines of.
<IfModule mod_perl.c>
PerlRequire /Users/<MyUsername>/Library/Perl/startup.pl
<Location "/Somewhere">
SetHandler perl-script
PerlHandler MyModule
</Location>
</IfModule>
In startup.pl enter your standard mod_perl start up configuration.
This may look something like this.
#!/usr/bin/perl
####################
# Description: mod_perl startup script to pre-load perl
# modules that will used when running the
# web servers perl modules
#
####################
# Standard Modules
use strict;
# Custom Modules
use lib "/Users/<MyUsername>/Library/Perl";
use MyModule;
####################
# Do some processing
1;
In the site configuration and startup.pl you’ll note that I’ve put my Perl code in my home directory under Library/Perl. This could be anywhere of course. If your server will host websites for many users that will each be setting up / developing / using their own mod_perl modules then you quite possibly don’t want to do this as you give each user with mod_perl essentially root access the server.
In my case, I’m in complete control of the modules and don’t see this configuration to present an unacceptable security risk.
Related posts:
mod_perl on Mac OS X Server (Leopard Server)