I am at a stage in life where I am going to be writing a lot of Perl code again. My preferred OS is Mac OS since it already comes with Perl 5.8.8 and Apache 2.2.9 (as of Mac OS 10.5.6). Unfortunately, mod_perl that ships with Mac OS, is broken (segfaults!). You can use fink or macports to pull Apache/Perl/mod_perl that work but I figured that if I use Ubuntu, I also get to be close to my Debian production environment. Here is how I got a fresh Ubuntu 8.10 Server VM ready with mod_perl:
Getting started
At one stage during the installation of Ubuntu server, you’ll be asked what components you want installed. Pick LAMP at the very least. After booting up for the first time (and logging in), fire up the following commands:
sudo bash #fire up a root shell so that we don't have to sudo every command
apt-get update
apt-get dist-update
reboot
#install things that could come in handy later
sudo bash
apt-get emacs #skip this if you prefer vi - it's already there
apt-get install linux-headers-server build-essential
At this stage you’ll have the latest kernel running. I find the default 80×24 display a little too restrictive. We’ll fix that by editing /boot/grub/menu.lst. Open the file in emacs or whatever editor you like, and scroll down to the end to a bunch of options that look like title, uuid, kernel, initrd. Append vga=0×31A to the end of the first kernel statement. e.g. in my case
kernel /boot/vmlinuz-2.6.27-9-server root=UUID=d9f9cc35-d880-494d-8cd3-92da418a438b ro quiet splash
became
kernel /boot/vmlinuz-2.6.27-9-server root=UUID=d9f9cc35-d880-494d-8cd3-92da418a438b ro quiet splash vga=0x31A
Reboot.
vga=0×31A gives me a resolution of 1280×1024 and 64k colors. Here are other options that you can play with:
# FRAMEBUFFER RESOLUTION SETTINGS
# +-------------------------------------------------+
# | 640x480 800x600 1024x768 1280x1024
# ----+--------------------------------------------
# 256 | 0x301=769 0x303=771 0x305=773 0x307=775
# 32K | 0x310=784 0x313=787 0x316=790 0x319=793
# 64K | 0x311=785 0x314=788 0x317=791 0x31A=794
# 16M | 0x312=786 0x315=789 0x318=792 0x31B=795
# +-------------------------------------------------+
Installing mod_perl
At this stage we already have Apache and Perl installed. If you do:
tail /var/log/apache2/error.log, you’ll see that out of the box, you only get support for PHP.
[Sun Dec 14 12:04:05 2008] [notice] Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4 with Suhosin-Patch configured -- resuming normal operations
Here is how you add mod_perl support:
sudo bash
apt-get install libapache2-mod-perl2
#restart apache so that it loads mod_perl
apache2ctl restart
#make sure that it did indeed load
tail /var/log/apache2/error.log
#if all went well, you'll see something to the effect of (emphasis mine):
[Sun Dec 14 12:19:17 2008] [notice] Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4 with Suhosin-Patch mod_perl/2.0.4 Perl/v5.10.0 configured -- resuming normal operations
Testing our mod_perl installation
Let’s write a simple mod_perl response handler to make sure our installation was successful. Create Hello.pm in your home directory – which is /home/deepakg/ on my machine:
package Hello;
use strict;
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::Const -compile => qw(OK);
sub handler {
my $r = shift;
$r->content_type('text/plain');
print "Hello World, the time here is " . localtime() . "\n";
return Apache2::Const::OK;
}
1;
Then to make sure that we didn’t make any typos:
perl -c Hello.pm
Hello.pm syntax OK
Next, open /etc/apache2/apache2.conf and type the following right at the end:
PerlRequire /home/deepakg/Hello.pm
<Location /time>
SetHandler perl-script
PerlResponseHandler Hello
</Location>
Restart apache and check the Apache error log to make sure that it started without any issues:
sudo apache2ctl restart
tail /var/log/apache2/error.log
Install lynx, so that you can check your handy work:
sudo apt-get install lynx
# and once it is installed
lynx http://localhost/time
If everything is working then you’ll be greeted with something like this:
Hello World, the time here is Sat Jan 10 15:25:51 2009
Of course, the actual date and time will vary on your system
.
Miscellaneous
If the time shown by the script above looks awkward, your time zone might not have been configured correctly. Configure the time zone to where you are:
sudo dpkg-reconfigure tzdata
And then may be tweak the clock by hand if needed:
sudo date MMDDhhmm #MM - month, DD - date, hh - hour (24 format), mm - minute
configuration, installation, perl, ubuntu
linux, mod_perl, perl, ubuntu