SME 5.x mod_perl HowTo  

Author:  Greg Zartman <greg@leiinc.com>
Contributor:
Darrell May  
Release supported: SME 5.x
License: GPL
Last updated: January 6, 2003 

 

 


Problem:  You want to get mod_perl running on your SME 5.x server.
Solution:
  SME 5.x comes with all of the mod_perl perl modules and Apache modules installed; they are simply not active on a stock SME box.  Follow this Howto to activate mod_perl on your SME 5.x server.


STEP 1:  Download the e-smith-mod_perl RPM:

http://www.leiinc.com/repository/Linux/Mitel_SME_Server/Contribs/mod_perl/e-smith-mod_perl-0.0.1-2.noarch.rpm

STEP 2:  Install e-smith-mod_perl RPM:

[root@testbed files]# rpm -ivh e-smith-mod_perl-0.0.1-1.noarch.rpm
Preparing... ########################################### [100%]
1:e-smith-mod_perl ########################################### [100%]
/usr/sbin/apachectl graceful: httpd gracefully restarted

STEP 3:  That's it!! Mod_perl is now active on your server.



Create an Apache alias to mod_perl 

STEP 1:  Create an httpd.conf template fragment, called 86modperl_primary, defining a mod_perl alias and <Location> section: 

[root@testbed root]# pico /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf/86modperl_primary

---- IN PICO----

#apply mod_perl to primary Ibay
alias /mod_perl/ /home/e-smith/files/primary/cgi-bin/
<Location /mod_perl/>
   SetHandler perl-script
   PerlHandler Apache::Registry
   Options +ExecCGI
   PerlSendHeader On
</Location>

Note: This fragment creates an httpd alias to the primary ibay cgi-bin that routes requests through mod_perl.  Perl scripts called with the url http://yourdomain.com/mod_perl/your_perl_app will be executed using the Apache::Registry perl handler.  Location of the perl script is the primary ibay cgi-bin, just like regular cgi scripts.  


STEP 2:  Expand the httpd.conf template fragments:

[root@testbed root]# /sbin/e-smith/expand-template /etc/httpd/conf/httpd.conf
[root@testbed root]#

STEP 3:  Restart Apache:

[root@testbed root]# /etc/rc.d/init.d/httpd graceful
/usr/sbin/apachectl graceful: httpd gracefully restarted
[root@testbed root]#

STEP 4:  Check Apache error log to make sure Apache restarted OK:

[root@testbed root]# pico /var/log/httpd/error_log

Scroll to the bottom of the log file and verify that no errors exist.



Test mod_perl

NOTE: This procedure assumes you have setup an Apache alias to mod_perl, as detailed above.

STEP 1:  CD to the primary ibay cgi-bin:

[root@testbed root]# cd /home/e-smith/files/primary/cgi-bin/

STEP 2:  Create a test perl script (we'll use a classic):

[root@testbed root]# pico tester.pl

 

------ IN PICO----

##Mod_perl Tester Script
use strict;
print "Content-type: text/html\n\n";
print "<HTML><BODY>";
print "<H2>HELLO WORLD!!!</H2>";
print "</BODY></HTML>";


STEP 3:  Save the script and exit pico.


STEP 4:  Compile the script to make sure it doesn't contain any errors:

[root@testbed cgi-bin]# perl -c tester.pl
tester.pl syntax OK
[root@testbed cgi-bin]#

STEP 5:  Set the permissions of the script so that Apache can execute it:

[root@testbed cgi-bin]# chown admin:shared tester.pl
[root@testbed cgi-bin]#

[root@testbed cgi-bin]# chmod 750 tester.pl
root@testbed cgi-bin]#


STEP 6:  Open a web browser on a client machine and browse to http://your_domain.com/mod_perl/tester.pl

If all is well, you will be greeted with a big:

HELLO WORLD!!!

What kind of a perl monger would we be if our first mod_perl script didn't display this classic message!!  ;-)


Additional Reading

It is highly recommended that those inexperienced with mod_perl spend some time reading about the subject prior to deploying apps in a production environment.  Mod_perl requires a much more structured approach to script development than that required with traditional cgi development.  Further, the developer needs to be aware of certain idiosyncrasies associated with running cached scripts on a multi-threading web server.

Suggested reading includes:

1. http://www.samag.com/documents/s=1287/sam03030011/

2. http://perl.apache.org/docs/1.0/guide/porting.html

3. http://perl.apache.org/docs/1.0/api/Apache.html