- 论坛徽章:
- 0
|
不知道为什么,原来的RedHat9.0不能用了,只好重新安装。
主要是没有有安装成功mod_perl。
1.Installation
First, download the mod_perl 2.0 source.
configure mod_perl:
% tar -xvzf mod_perl-2.0-current.tar.gz
% cd mod_perl-1.99_17
% perl Makefile.PL MP_APXS=/usr/local/apache2/bin/apxs MP_INST_APACHE2=1
where MP_APXS is the full path to the apxs executable, normally found in the same directory as the httpd executable, but could be put in a different path as well.
notes:
[warning] mod_perl dso library will be built as mod_perl.so
[warning] You'll need to add the following to httpd.conf:
[warning] LoadModule perl_module modules/mod_perl.so
[warning] Apache Perl modules will be installed relative to Apache2/
[warning] Don't forget to:
[warning] - configure 'PerlModule Apache2' in httpd.conf
[warning] - or 'use Apache2 ();' in a startup script
Finally, build, test and install mod_perl:
% make && make test && make install
Become root before doing make install if installing system-wide.
2.Configuration
Enable mod_perl built as DSO, by adding to httpd.conf:
LoadModule perl_module modules/mod_perl.so
Next, tell Perl where to find mod_perl2 libraries:
PerlModule Apache2
If you want to run mod_perl 1.0 code on mod_perl 2.0 server enable the compatibility layer:
PerlModule Apache::compat
3.Server Launch and Shutdown
Apache is normally launched with apachectl:
% $HOME/httpd/prefork/bin/apachectl start and shut down with:
% $HOME/httpd/prefork/bin/apachectl stop
Check $HOME/httpd/prefork/logs/error_log to see that the server has started and it's a right one. It should say something similar to:
[Sun Nov 14 12:48:34 2004] [notice] Apache/2.0.51 (Unix) mod_perl/1.99_17 Perl/v5.8.0 mod_ssl/2.0.51 OpenSSL/0.9.7d PHP/5.0.1 configured -- resuming normal operations
4.Registry Scripts
To enable registry scripts add to httpd.conf:
Alias /perl/ /www/141.44/perl/
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
Options +ExecCGI
and now assuming that we have the following script:
#!/usr/bin/perl
print "Content-type: text/plain ";
print "mod_perl 2.0 rocks! ";
saved in /www/141.44/perl//rock.pl. Make the script executable and readable by everybody:
% chmod a+rx /home/httpd/httpd-2.0/perl/rock.pl
Of course the path to the script should be readable by the server too. In the real world you probably want to have a tighter permissions, but for the purpose of testing that things are working this is just fine.
Now restart the server and issue a request to
http://localhost/perl/rock.pl
and you should get the response:
mod_perl 2.0 rocks!
If that didn't work check the error_log file.
5.Handler Modules
Finally check that you can run mod_perl handlers. Let's write a response handler similar to the registry script from the previous section:
#file:MyApache/Rocks.pm
#----------------------
package MyApache::Rocks;
use strict;
use warnings;
use Apache::RequestRec ();
use Apache::RequestIO ();
use Apache::Const -compile => qw(OK);
sub handler {
my $r = shift;
$r->content_type('text/plain');
print "mod_perl 2.0 rocks! ";
return Apache::OK;
}
1;
Save the code in the file MyApache/Rocks.pm, somewhere where mod_perl can find it. For example let's put it under /home/httpd/httpd-2.0/perl/MyApache/Rocks.pm, and we tell mod_perl that /home/httpd/httpd-2.0/perl/ is in @INC, via a startup file which includes just:
use lib qw(/www/141.44/perl);
1;
and loaded from httpd.conf:
PerlRequire /www/141.44/perl/startup.pl
Now we can configure our module in httpd.conf:
SetHandler perl-script
PerlResponseHandler MyApache::Rocks
Now restart the server and issue a request to
http://localhost/rocks
and you should get the response:
mod_perl 2.0 rocks!
If that didn't work check the error_log file.
6.Apache 2.0 is required. mod_perl 2.0 does not work with Apache 1.3
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/8979/showart_63468.html |
|