Linux programming environment described in Mod_perl

2011-06-04  来源:本站原创  分类:OS  人气:82 

You are viewing Linux | Unix is ​​Linux programming environment described in the Mod_perl
1 Introductory Guide
mod_perl is a huge and complex tool, it built a number of modules to help you easily build dynamic Web site. The purpose of this guide is to help you build a good mod_perl module, and from understanding mod_perl implementation technology. I do not recommend using the techniques described here to build a large site, especially for a people who had just set foot in mod_perl. But I recommend you look at it in depth some of the built-in programs, such as Mason, AxKit, EmbPerl, Apache:: ASP and PageKit and so on.

1.1 What do you need?
This guide assumes that you have had experience in installing and testing mod_perl. And a newer version of the Apache installation experience. Because you may need on your machine when the appropriate changes to achieve the configuration in this article. We need to install some modules and you need to enter the Apache configuration directory for changes. So the best you have root privileges to do these things. Of course, you also need a text editor.

1.2. To the point
mod_perl module is a Perl module, but it has a more special design. The most convenient way to create a Perl module that uses the standard Perl distribution comes with a tool h2xs. You can type in command line mode to see h2xs its parameter list. Now, to an appropriate directory to start a new project, type:

h2xs-A-X-n Apache:: Tutorial:: First

h2xs will create the directory Apache, and other subdirectories. now look at the directory into the deepest level:

cd Apache / Tutorial / First

In this new directory, you can see five files: Changes,, MANIFEST, Makefile.PL and Their role is as follows:


This file changes as your project log (changelog) file

This is the main module file that contains your mod_perl handler code (handler code).


This file is used to automatically build a tar.gz version of the module type distribution. So you can get your CPAN module released or distributed to others. It contains all your files in the project list.


This is the standard Perl Makefile constructor. Used to create the Makefile.PL file to compile the module.

Some of the modules for the test script. By default it will just check the module compiled and loaded

Well, now we can begin to work into the mod_perl module. Use a text editor to open the file, modified as follows:

package Apache:: Tutorial:: First;

use strict;

use vars qw / $ VERSION /;

use Apache:: Constants;

$ VERSION = 0.01;

sub handler {

my $ r = shift;

$ R-> send_http_header ('text / html');

print "<html> <body> Hello World </ body> </ html>";

return OK;



Do not forget the end of the file "1;" For Perl, a module to return the last non-zero value indicates that the module has been successfully compiled.

1.3 Installing the modules you
h2xs tools to make installation of our module is very convenient. And your files in the same directory. , And type:

perl Makefile.PL


make test

If the make test is successful, you need to run as root:

make install

So you put your module into the perl library directory (library directory).

1.4 Add the module for Apache, a handle (handler) Now we need to modify the configuration directory into the Apache configuration file, so that we as an Apache module content processing stage of the processor. Open the httpd.conf file, add the following configuration at the end:

<Location /mod_perl_tutorial>

SetHandler perl-script

PerlHandler Apache:: Tutorial:: First

</ Location>

Then save the configuration file, and restart apache server:

apachectl stop

apachectl start

Now use the browser to access http://localhost/mod_perl_tutorial, you will see the show as scheduled "Hello World" page.

2. What happened here? Well, here is what happened then?

When Apache starts, it reads its configuration instructions and the appropriate command to the appropriate processing of the command module. There are two related directives SetHandler and PerlHandler.

The first directive SetHandler handled by the mod_mime module, what the instructions said to use the module as a major part of processing the request. This set of perl-script that use mod_perl to handle the request.

The second command PerlHandler by the mod_perl module to handle, it's just simple instructions to use our module to handle the major part of the request. It is important to note that whenever you have a PerlHandler, you need the appropriate configuration directives SetHandler perl-script. In order to make your mod_perl code work. I always think this is a weakness, but this will involve Apache internal processing mechanism, so it is difficult to change in the future.

Now request a, Apache see what modules to handle the URI, and here decided to use mod_perl, and mod_perl knows it must send the request to our module, and calls our module's handler () function as Apache:: Request object The first argument. Our handler () return value determines the next Apache will do. OK now we know that the return value means that every success. OK is from Apache:: Constants module exports constants.

3 debugging <br /> If you do not see "Hello World", you may see an error page, or something completely different. The first step in the end to see the error log to see what error occurred. I used to request in the browser immediately after the error log. You can use the tail tools:

tail-f / path / to / apache / logs / error_log

(Use your real error_log path to replace the above path, if you're not sure where it is, check your httpd.conf file ErrorLog directive part)

Now reload the page, then error_log will tell you where there is a problem. More about perl debugging, see perldebug.

4. <br /> Add more for now if you want to make some changes to the above situation, how? Unfortunately, the only installation mode as follows:

Modify your file

Re-run make install as root

Restart Apache

This may be very troublesome, especially to restart Apache. To address this problem, we can also install a specially designed module to avoid having trouble doing so. First you need to download it from CPAN and install Apache:: Reload module (unless you've been using mod_perl 1.26 or later). Here download.

Tar.gz file and unlock new directory, run:

perl Makefile.PL


Then to run as root:

make install

Now re-open the httpd.conf file, add:

PerlInitHandler Apache:: Reload

This change will test all the modules and reloaded automatically when needed a new module. This is useful for the development, but there will be a performance penalty, so the development is complete, turn off the feature.

  • Linux programming environment described in Mod_perl 2011-06-04

    You are viewing Linux | Unix is ​​Linux programming environment described in the Mod_perl 1 Introductory Guide mod_perl is a huge and complex tool, it built a number of modules to help you easily build dynamic Web site. The purpose of this guide is t

  • Advanced UNIX Programming Environment (2nd Edition) 2011-01-05

    Advanced UNIX Programming Environment (2nd Edition) is a 09 year bestsellers TOP50, 08 year bestsellers TOP50. Original Title: Advanced Programming in the UNIX Environment Original Press: Addison-Wesley Author: (United States) W. Richard Stevens, Ste

  • linux c language programming environment to build 2010-10-09

    inux c language programming environment to build Need the following software and development kits: terminal terminal gcc / / compiler cpp libgcc libc6 / / standard library math functions library directory in binutils / / Connection Kit / Us

  • Qt programming environment under Windows configuration 2010-03-19

    Eclipse + CDT + MinGW: Windows + QT + Eclipse + MinGW tutorial build QT development environment more Keyword: c + + qt eclipse mingw Windows + QT + Eclipse + MinGW detailed tutorial build QT development environme

  • Advanced Linux Programming Chapter III: Process 2010-04-25

    Advanced Linux Programming Chapter One: Getting Started Advanced Linux Programming Chapter II: Preparation of a good Linux software Each process has a unique pr

  • Ten essential Linux development environment development tools / Linux development tools Daquan / Linux Web Development Tools 2010-08-04

    Ten essential Linux development environment development tools / Linux development tools Daquan / Linux Web Development Tools 2009-03-26 10:14 Keywords: LINUX tool development environment for programming software Articles from

  • unix programming environment for the implementation of learning examples 2010-08-12 A Recently learning Linux programming, really a lot of harvest. Before all others, or man to tell you how to use a command, but now I realize that is the source code determines all. linux programming, firs

  • Taught you how to put Vim into an IDE programming environment converted 1 2010-10-01

    Taught you how to put Vim into an IDE programming environment modification (Photo) By: Wu Yin Date: 2007-09-07 Version: 0.5 Email: # Homepage: Copyright: Copyright of the article by Wu Yin and his love

  • Reprinted - Linux development environment tools 2010-11-12

    Blog page up and exchange proposed adding Links recommended list of complaints Search: Help Snake dance snake Millennium, the Millennium cultivation; snake dance, air swallowing the sky. * Management blog * Published an article * Me

  • Reproduced - Linux development environment tools 2010-11-12

    Blog home register and exchange proposed adding Links recommended list of complaints Search: Help Snake dance snake Millennium, Millennium cultivation; snake dancing, air swallowing the sky. * Management blog * Posts * Message * Fav

  • Configuration of the Python programming environment based on VIM 2010-03-17

    1, configuration files in the directory / etc / or / etc / vim / Here, there is a document called the vimrc, which is the system common vim configuration files are valid for all users. In each user's home directory, can build their own private config

  • linux set environment variables 2010-09-14

    linux set environment variables 1 Introduction In linux system, if you download and install the application, is likely to type its name when "command not found" prompt content. If the target every time to the installation folder, locate the exec

  • Linux Programming Study Notes 1 2010-09-14

    Chapter Introduction 1.1 UNIX, Linux and the GNU Introduction Briefed UNIX, Linux, and GUN the history and development. Noted that the programming philosophy of UNIX, Linux should also follow its programming philosophy. Simplicity, the program small

  • Book Recommendation: Linux programming interface (The Linux Programming Interface) 2010-09-25

    Related links: amazon nostarch Press Quote The Linux Programming Interface is the definitive guide to the Linux and UNIX programming interface-the interface employed by nearly every application that runs on a Linux or UNIX system. In this authoritati

  • Android Tutorial II: Linux development environment for the next build Android 2010-11-12

    Speaking in the window under the previous development environment to build Android, the overall relatively simple. This time to talk about the Linux development environment to build Android, very popular here, mainly in the Ubuntu operating system, f

  • Under linux set environment variables at startup and software installation 2010-12-23

    1, set the startup environment variables from the configuration In the Linux terminal environment, export command can be used to set environment variables, but it set the variable disappears immediately after you close the terminal. If you want to se

  • linux jdk environment configuration 2011-01-06

    Linux jdk environment variable settings Steps: / etc / profile.d 2.touch / / shell file 3. write the following: # Set java_environment JAVA_HOME = jdk path export JAVA_HOME CLASSPATH = $ CLASSPATH: $ JAVA_HOME / jre / lib export

  • Java code to dynamically set by the Linux system environment variables 2010-12-03

    First, a few nonsense, the original has been written in this article Netease blog, but imagined or JE in comparison to the force and then to do a very difficult decision, since there is need to record something to write here. Oh. Today java code that

  • Book: Unix Programming Environment 2011-09-18

    Unix Programming Environment

  • Linux Socket Programming Environment 2010-09-26

    What is Socket Socket interface is a TCP / IP network, API, Socket Interface defines a number of functions or routines that programmers can use them to develop TCP / IP network applications. To learn on the Internet TCP / IP network programming, we m