Apache支持perl在web的应用
apache支持perl在web的应用
1、安装apache
如apache安装在/usr/local/apache2/
2、安装perl
perl默认在linux系统里是自带的,
PS:要注意安装版本的差异,版本过低会报错
Can’t locate Apache/Response.pm in @INC …
Found this issue in Aurora SPARC Linux 2.0 (Fedora Core 3 for SPARC) when trying to install… turns out that after installing all the modules for rt, I still had an ancient verion of CGI.pm, which was not intended to correctly detect the mod_perl2 modules vs. regular mod_perl. Upgrading CGI via CPAN quickly resolved this problem after an embarrassing number of hours troubleshooting.
If Apache refuses to start after you add PerlRequire bin/webmux.pl to your config and you’re sure you’ve got a valid mod_perl2 installation, try upgrading CGI to the latest version.
3、安装mod_perl
如我现在版本
tar zxvf mod_perl-2.0-current.tar.gz
cd mod_perl-2.0.4
perl Makefile.PL
make
make test
make install
PS:如果apache在运行帐号的权限是nobody的话,而mod_perl-2.0.4是在root在目录下,在make test的过程将会报错
You are running the test suite under user ‘root’.
Apache cannot spawn child processes as ‘root’, therefore
we attempt to run the test suite with user ‘nobody’ (99:99).
The problem is that the path (including all parent directories):
/root/mod_perl-2.0.4/t
must be ‘rwx’ by user ‘nobody’, so Apache can read and write under that
path.
建议将mod_perl-2.0.4 放在/tmp目录下
安装后将会在/usr/local/apache2/modules/有一个mod_perl.so
ls /usr/local/apache2/modules/mod_perl.so
4、配置http.conf
在http.conf里
a、载入模块
LoadModule perl_module modules/mod_perl.so
b、<IfModule mime_module>里加入后缀解析
AddHandler cgi-script .cgi .pl
c、vhost设置里加入执行
<VirtualHost *:80>
ServerName www.588k.com
DocumentRoot /opt/wwwroot/www.588k.com
ScriptAlias /perl/ “/opt/wwwroot/www.588k.com/perl/” ##/opt/wwwroot/www.588k.com/perl为网站的documentroot的perl目录<Location /perl>
SetHandler perl-script
PerlHandler ModPerl::Registry
Options +ExecCGI
allow from all
PerlSendHeader On
</Location>
</VirtualHost>
5、测试
先重启apache
在documentroot下建立test.pl 内容如下
#!/usr/bin/perl -w
use CGI;
{
my $q = new CGI;
print $q->header(),
$q->start_html(”hello perl world!”),
$q->h1(’hello perl world, by sakia’),
$q->end_html();
}
通过http://www.588k.com/perl/test.pl如果能够正常输出
hello perl world, by sakia
配置成功