By Stas Bekman, Eric Cholet
Book Price: $49.95 USD
£35.50 GBP
PDF Price: $39.99
Cover | Table of Contents | Online Book | Colophon
Apache::Registry and
Apache::PerlRun modules.STDIN and write to STDOUT,
regardless of whether it is interpreted (e.g., the Unix shell),
compiled (e.g., C or C++), or a combination of both (e.g., Perl). The
first CGI programs were written in C and needed to be compiled into
binary executables. For this reason, the directory from which the
compiled CGI programs were executed was named
cgi-bin, and the source files directory was
named cgi-src. Nowadays most servers come with a
preconfigured directory for CGI programs called, as you have probably
guessed, cgi-bin.MaxRequestsPerChild
.
This directive specifies the number of requests that should be served
by the child before it is instructed to step down and is replaced by
another process. Figure 1-3 illustrates.
ListenBacklog
configuration directive. When this number is reached, a client
issuing a new request will receive an error response informing it
that the server is unreachable.
ScriptAlias. This translation can be completely
modified by modules such as mod_rewrite, which
register themselves with Apache to be invoked in this phase of the
request processing.http://hoohoo.ncsa.uiuc.edu/cgi/
http://www.w3.org/Protocols/rfc2616/rfc2616.html
http://www.w3.org/CGI/
http://www.ietf.org/rfc/rfc2046.txt
http://modules.apache.org/
http://www.modperl.com/
http://www.modperlcookbook.org/.http://perl.apache.org/download/binaries.html.
Windows users may skip to Section 2.4.panic% make -v panic% gcc -v panic% perl -v
Command not found,
the utility will need to be installed.http://www.apache.org/dist/httpd/ and
http://perl.apache.org/dist/, respectively.panic% cd /home/stas/src
panic% tar -zvxf apache_1.3.xx.tar.gz
panic% tar -zvxf mod_perl-1.xx.tar.gz
panic% cd mod_perl-1.xx
panic% perl Makefile.PL APACHE_SRC=../apache_1.3.xx/src \
APACHE_PREFIX=/home/httpd DO_HTTPD=1 USE_APACI=1 EVERYTHING=1
panic% make && make test
panic% su
panic# make installhttp://www.apache.org/dist/httpd/ and
http://perl.apache.org/dist/ and
are also available from mirror sites. Even if you have the Apache
server running on your machine, you'll need its
source distribution to rebuild it from scratch with mod_perl.panic% cd /home/stas/src
panic% tar -zvxf apache_1.3.xx.tar.gz panic% tar -zvxf mod_perl-1.xx.tar.gz
panic% gzip -dc apache_1.3.xx.tar.gz | tar -xvf - panic% gzip -dc mod_perl-1.xx.tar.gz | tar -xvf -
http://www.gnu.org/, among other
sources. The GNU versions are available for every platform that
Apache supports.ServerName, Port,
User, Group,
ServerAdmin, DocumentRoot, and
a few others. There are helpful hints preceding each directive in the
configuration files themselves, with further information in
Apache's documentation. Follow the advice in the
files and documentation if in doubt.panic# /usr/local/apache/bin/apachectl start
panic# /usr/local/apache/bin/apachectl stop
80 or
another privileged port, the user executing
apachectl must be root.[Thu Jun 22 17:14:07 2000] [notice] Apache/1.3.12 (Unix) mod_perl/1.24 configured -- resuming normal operations
ServerName directive. If the
Port directive has been set with a value other
than 80, add this port number to the end of the
server name. For example, if the port is 8080, test the server with
http://localhost:8080/ or
http://example.com:8080/. The
"It Worked!" page, which is an
index.html file that is installed automatically
when running http://perl.apache.org/download/binaries.html.
This self-extracting archive yields four directories:
Apache/, Perl/,
openssl/, and readmes/.SET PATH=C:\Perl\5.6.1\bin;C:\Perl\5.6.1\bin\MSWin32-x86;"%PATH%"
panic% mkdir /home/stas/modperl
User directive, typically
nobody. You can modify the
User directive to run the server under your
username, for example:User stas
rwx------, set the directory permissions to:panic% chmod 0700 /home/stas/modperl
rwxr-xr-x or 0755 for your
files and directories. This is insecure, because other users on the
same machine can read your files.panic# chmod 0755 /home/stas/modperl
0700.print "Content-type: text/plain\n\n"; print "mod_perl rules!\n";
#! line (colloquially known as the
shebang line) is not needed with mod_perl,
although having one causes no problems, as can be seen in Example 2-2.#!/usr/bin/perl print "Content-type: text/plain\n\n"; print "mod_perl rules!\n";
panic% chmod 0700 /home/stas/modperl/mod_perl_rules1.pl
panic% perl /home/stas/modperl/mod_perl_rules1.pl
Content-type: text/plain mod_perl rules!
http://localhost/perl/mod_perl_rules1.pl
http://localhost:8080/perl/mod_perl_rules1.pl
localhost approach will work only if the
browser is running on the same machine as the server. If not, use the
real server name for this test. For example:http://example.com/perl/mod_perl_rules1.pl
handler subroutine, add a statement to return the
status to the server when the subroutine has successfully completed,
and add a package declaration at the top of the code.package ModPerl::Rules1;
use Apache::Constants qw(:common);
sub handler {
print "Content-type: text/plain\n\n";
print "mod_perl rules!\n";
return OK; # We must return a status to mod_perl
}
1; # This is a perl module so we must return true to perlpackage ModPerl::Rules2;
use Apache::Constants qw(:common);
sub handler {
my $r = shift;
$r->send_http_header('text/plain');
$r->print("mod_perl rules!\n");
return OK; # We must return a status to mod_perl
}
1; # This is a perl module so we must return true to perl@INC (e.g., under
/usr/lib/perl5/site_perl/5.6.1), and put
Rules1.pm and Rules2.pm
into it. (Note that you will need root access in
order to do this.) The files should include the code from the above
examples. To find out what the @INC directories
are, execute:panic% perl -le 'print join "\n", @INC'
http://www.apache.org/.http://perl.apache.org/.http://cpan.org/
libwww-perl home page: http://www.linpro.no/lwp/.libwww-perl
distribution is a collection of Perl modules and programs that
provide a simple and consistent programming interface (API) to the
World Wide Web. The main focus of the library is to provide classes
and functions that facilitate writing WWW clients; thus,
libwww-perl is said to be a WWW client library.
The library also contains modules that are of more general use, as
well as some useful programs.panic% cd /home/stas/src panic% tar xzvf apache_1.3.xx.tar.gz panic% tar xzvf mod_perl-1.xx.tar.gz panic% cd mod_perl-1.xx panic% perl Makefile.PL APACHE_SRC=../apache_1.3.xx/src \ DO_HTTPD=1 USE_APACI=1 EVERYTHING=1 panic% make && make test panic# make install panic# cd ../apache_1.3.xx panic# make install
EVERYTHING=1 enables a lot of options for you,
whether you actually need them or not. You may want to enable only
the required options, to squeeze even more juice out of mod_perl. You
may want to build mod_perl as a loadable object instead of compiling
it into Apache, so that it can be upgraded without rebuilding Apache
itself. You may also want to install other Apache components, such as
PHP or mod_ssl, alongside mod_perl.panic% perl Makefile.PL [parameters].
panic% make
Config.pm module and can be displayed with the
Perl -V command. All these options are reapplied
when compiling Perl modules.panic% make test
panic% perl Makefile.PL PORT=xxxx
TEST_VERBOSE
parameter:panic% make test TEST_VERBOSE=1
APACHE_USER and APACHE_GROUP to
override the default User and
Group settings in the
httpd.conf file used for make
test. These two variables should be set before the
Makefile is created to take effect during the
testing stage. For example, if you want to set them to
httpd, you can do the following in the
Bourne-style shell:panic% export APACHE_USER=httpd panic% export APACHE_GROUP=httpd panic% perl Makefile.PL ...
panic% perl t/TEST -v modules/file.t
panic% perl t/TEST modules
panic% make start_httpd
panic% make kill_httpd
panic# make install
panic# cd ../apache_1.3.xx panic# make install
APACHE_PREFIX
option as explained earlier in this chapter, you can skip this step.NO_HTTPD=1 option during the perl
Makefile.PL (mod_perl build) stage. Then you will have to
configure various things by hand and proceed to build Apache. You
shouldn't run perl Makefile.PL
before following the steps described in this section.ALL_HOOKS=1).AddModule modules/perl/libperl.a
EXTRA_LIBS:EXTRA_LIBS=`perl -MExtUtils::Embed -e ldopts`
EXTRA_CFLAGS:EXTRA_CFLAGS=`perl -MExtUtils::Embed -e ccopts`
panic% cp -r src/modules/perl apache_1.3.xx/src/modules/
panic% perl Makefile.PL NO_HTTPD=1 DYNAMIC=1 EVERYTHING=1 \
APACHE_SRC=../apache_1.3.xx/srcUSE_APACI=1):panic% tar xzvf apache_1.3.xx.tar.gz
panic% tar xzvf mod_perl-1.xx.tar.gz
panic% cd mod_perl-1.xx
panic% perl Makefile.PL APACHE_SRC=../apache_1.3.xx/src \
DO_HTTPD=1 USE_APACI=1 EVERYTHING=1
panic% make && make test
panic# make install
panic# cd ../apache_1.3.xx
panic# make installhttp://perl.apache.org/download/ to learn the
version number of the latest stable release of mod_perl 1, and
download the appropriate file.Apache: http://www.apache.org/dist/httpd/ mod_perl: http://perl.apache.org/download/ PHP: http://www.php.net/downloads.php
panic% tar xvzf mod_perl-1.xx panic% tar xvzf apache_1.3.xx.tar.gz panic% tar xvzf php-x.x.xx.tar.gz
CPAN.pm module, which provides, among other
features, a shell interface to the CPAN repository (see the Preface).panic% perl -MCPAN -eshell
cpan prompt:cpan>