2006-10-04 Mod perl and Slackware part 2

The previous day, I thought I had Apache with mod_perl working on Slackware 10.2, but alas, funny segfaults all over the place. This time, I installed mod_perl in a completely separate user account and it works.

As root, create a user:

        # useradd -g users -m -s /bin/bash apache_mod_perl
        # passwd apache_mod_perl

Login as the new user, then:

        $ mkdir bin lib perl_modules
        $ wget http://search.cpan.org/CPAN/authors/id/L/LD/LDS/CGI.pm-3.25.tar.gz
        $ tar xfz CGI.pm-3.25.tar.gz
        $ cd CGI.pm-3.25/
        $ perl Makefile.PL PREFIX=$HOME
        $ make && make install

Add the following line to .bash_profile:

        export PERLLIB=$PERLLIB:$HOME/lib/perl5/5.8.6:\

And logout/login.

        $ mkdir -p $HOME/.cpan/CPAN
        $ cp /usr/lib/perl5/5.8.6/CPAN/Config.pm .cpan/CPAN/
        $ vi .cpan/CPAN/Config.pm

Edit the file and change all paths with 'home' in them to the home directory of the current user (apache_mod_perl). Also change line:

        'makepl_arg' => q[],


        'makepl_arg' => q[PREFIX=/home/apache_mod_perl],

Save and exit, and install any additional Perl modules your application needs. In our case, we typed:

        perl -MCPAN -e shell
        cpan> install  XML::Simple IPC::Cache
        Exit the cpan shell.
        $ mkdir ~/src
        $ cd ~/src
        $ wget http://ftp.bit.nl/mirror/slackware/slackware-10.2/source/n/apache/apache_1.3.33.tar.gz
        $ wget http://perl.apache.org/dist/mod_perl-1.0-current.tar.gz
        $ tar xfz apache*
        $ tar xfz mod*
        $ cd mod*
        $ perl Makefile.PL PREFIX=$HOME APACHE_PREFIX=$HOME/apache \
          APACHE_SRC=../apache_1.3.33/src DO_HTTPD=1 USE_APACI=1 EVERYTHING=1
        $ make && make install && cd ../apache_1.3.33/ && make install

Now edit /home/apache_mod_perl/apache/conf/httpd.conf and:

Save, exit and edit ~/.bash_profile. Add the following line:

        export PATH=$HOME/apache/bin:$PATH

Logout and login. Type:

        $ apachectl start
        $ cat apache/logs/error_log

It should say something like:

        "Apache/1.3.33 (Unix) mod_perl/1.29 configured"

You want users to be able to execute Perl scripts. Edit ~/apache/conf/httpd.conf and add the following lines at the end (only do this if you know each and every option below and understand the security risks):

  # Line below checks all modules for changes, only necessary for development
  PerlModule Apache::StatINC
  <Directory /home/*/public_html>
    Options MultiViews Indexes FollowSymlinks ExecCGI
    <Files *pl>
      SetHandler perl-script
      PerlHandler Apache::Registry
      Options ExecCGI FollowSymLinks
      allow from all
      PerlSendHeader On
      # Line below checks all modules for changes, only necessary for development
      PerlInitHandler Apache::StatINC

To set the directory for modules:

  <Directory /home/someuser/public_html>
    PerlSetEnv "PERL5LIB" "/home/someuser/src/project/perl/lib"

Restart apache with:

  $ apachectl restart

Go to http://localhost:8080/someuser/thescript.pl and be astounded.