参考官网
用perl开发网站有很多方法,我用的是Handler Modules 这种方法简单可靠
1首先安装apache2,和mod_perl (ubuntu下叫libapache2-mod-perl)
这在ubuntu下都极为方便,
2配置apache
<VirtualHost *:80>
DocumentRoot /home/sma/cgi-bin
ServerName www.per.com
CustomLog /var/log/apache2/per.com.log combined
PerlRequire /home/sma/cgi-bin/etc/startup.pl
<Location /hello_word>
SetHandler perl-script
PerlHandler Way::Hello
</Location>
</VirtualHost>
这几行配置了一个虚拟主机,在我的家目录里/cgi-bin/etc/startup.pl为
use strict;
# Tell mod_perl where to find Hello.pm module
use lib qw(home/sma/cgi-bin/lib);
# The name of the module to load using mod_perl
use Way::Hello;
1;
/home/sma/cgi-bin/lib/Way/写一个Hello.pm
package Way::Hello;
use strict;
use warnings;
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::Const -compile => qw(OK);
sub handler {
my $r = shift;
$r->content_type('text/plain');
print "mod_perl 2.0 rocks!\n";
return Apache2::Const::OK;
}
1;
最后在hosts文件加入www.per.com,重启apache
即可访问www.per.com/hello_word