Last week you found out all sorts of good things about mod_perl, but you may be wondering how you get started using it. Let this article be your guide.
If you didn't have the courage to try the steps in the previous section or you simply want to understand more before you try, let's go through the fine details of the installation process. If you have successfully installed mod_perl following the short scenario in the previous section, you can skip this section and move on to the next one.
Before we proceed, I should note that you have to become a root user in order to install the files in a protected area. If you don't have root access, you can install all the files under your home directory as well. We will talk about the nuances of this approach in a future articles. I'll also assume that you have perl and gcc or an equivalent C compiler installed.
I assume that all builds are being done in the /home/stas/src directory. So we go into this directory.
% cd /home/stas/src
Now we download the latest source distributions of Apache and mod_perl. If
you have the LWP module installed (also known as libwww and available from CPAN), you should have the lwp-download utility that partly imitates your favorite browser by allowing you to download files from the Internet. You can use any other method to retrieve these files. Just make sure that you save both files in the /home/stas/src directory, as this will make it easier for you to follow the example installation process. Of course you can install both packages anywhere on your file system.
You can make sure that you're downloading the latest stable versions by
visiting the following distribution directories: http://www.apache.org/dist/httpd/ and http://perl.apache.org/dist/. As you have guessed already, the former URL is the main Apache distribution directory, the latter is the same thing for mod_perl.
Untar both sources. You have to uncompress and untar the files. In addition to its main usage for tarring and untarring files, the GNU tar utility is able to uncompress files compressed by the gzip utility, when the -z option is used.
% tar -zvxf apache_1.3.20.tar.gz
% tar -zvxf mod_perl-1.26.tar.gz
If you have a non-GNU tar utility, chances are that it will be unable to
decompress, so you need to do it in two steps. First uncompress the packages with:
mod_perl accepts a variety of parameters, in this scenario we are going to use those that will allow you to do almost everything with mod_perl. Once you learn more about mod_perl you will be able to fine tune the list of parameters passed to Makefile.PL. In future articles I'll go through all the available options.
perl Makefile.PL ... execution will check for prerequisites and tell you which required software packages are missing from your system. If you don't have some of the Perl packages installed, you will have to install these before you proceed. They all are available from CPAN and can be easily downloaded and installed.
If you choose to install mod_perl with help of the CPAN.pm module, it will install all the missing modules for you. To do so, tell CPAN.pm to install the Bundle::Apache bundle.
This step also executes the ./configure script from Apache's source distribution directory (absolutely transparently for you), which prepares the Apache build configuration files. If you need to pass parameters to Apache's ./configure script, just pass them as options to perl Makefile.PL .... In future articles we will talk about all the available options.
Now you should build the httpd executable by using the make utility.
% make
This command prepares mod_perl extension files, installs them in the
Apache source tree and builds the httpd executable (the web server itself) by compiling all the required files. Upon completion of the make process you get returned to the mod_perl source distribution directory.
make test executes various mod_perl tests on the freshly built httpd executable.
% make test
This command starts the server on a non-standard port (8529) and tests
whether all parts of the built server function correctly. If something goes wrong, the process will report it to you.
make install completes the installation process of mod_perl by installing all the Perl files required for mod_perl to run and of course the server documentation (man pages).
% make install
You can use the following commands concatenation style:
% make && make test && make install
It simplifies the installation, since you don't have to wait for each
command to complete before starting the next one. When installing mod_perl for the first time, it's better to do it step by step.
If you choose the all-in-one approach, you should know that if make fails, neither make test nor make install will be executed. If make test fails, make install will be not executed.
Finally, change to the Apache source distribution directory and run make install to create the Apache directory tree and install Apache header files (*.h), default configuration files (*.conf), the httpd executable and a few other programs.
% cd ../apache_1.3.20
% make install
Note that, as with a plain Apache installation, any configuration files
left from a previous installation won't be overwritten by this process. You don't need to backup your previously working configuration files before the installation.
When the make install process completes, it will tell you how to start a freshly built web server (the path to the apachectl utility that is being used to control the server) and where the installed configuration files are. Remember or even better write down both of them, since you will need this information very soon. On my machine the two important paths are:
So far we have completed the building and installation of the mod_perl enabled Apache. The next steps are to configure httpd.conf, write a little test script, start the server and check that the test script is working.