说明:此文档安装前提已经安装了perl环境,由于各系统不同,可能需要自行安装perl,最好安装perl10 或perl12版本
1安装apapche
yum search apache
这里我选择
httpd.x86_64 : Apache HTTP Server
httpd-devel.x86_64 : Development interfaces for the Apache HTTP server
yum install 相关文件(ex:yum install httpd.x86_64)
根据提示进行相关选择
2 安装mod_perl
mod_perl.x86_64 : An embedded Perl interpreter for the Apache HTTP Server
yum install mod_perl.x86_64
安装完成会生成mod_perl.so文件
find . -name mod_perl.so查看文件位置
在httpd.conf 配置文件中添加
LoadModule perl_module modules/mod_perl.so
注:此文件/etc/httpd/conf.d/perl.con 是否包含该选项,若存在就不需在httpd.conf 文件中配置。
httpd -t -D DUMP_MODULES 查看是否安装成功
出现perl_module (shared) 则安装成功
同时在httpd,conf 配置文件中作如下配置
AddHandler cgi-script .cgi .pl
<Directory "your dir">
AllowOverride All
#Options +ExecCGI
Options All
Order allow,deny
Allow from all
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
#PerlOptions +ParseHeaders
#PerlSendHeader On
</Directory>
这样就能访问你的pl文件了
测试
print "Content-type: text/html;\n\n";
print "<span class='' style='color:#f00'>Hello worlld</span>";
出现红色的Hello world 配置cgi成功
3.安装 apxs, 注:安装前检测是否安装有apxs
按此方法安装apace是没有apxs的
yum search apxs
yum install httpd-devel.x86_64
find . -name apxs
/usr/sbin/apxs
查找到文件is ok
4安装expat XML分析库
yum search expat
yum install expat.x86_64
5 安装cpan
yum search cpan
yum install perl-CPAN.x86_64
安装好cpan
cpan 进入安装环境
install LWP
install YAML
安装好过就能安心安装其他模块了,以后根据缺失什么就install相关模块
6.以上3,4,5步安装成功接下进行libapreq2的安装
perl -MCPAN -e "get Apache2::Request"
此过程需要时间请耐心等待
.....
cd ~/.cpan/build
perl Makefile.pl --with-apache2-apxs = /usr/sbin/apxs
make install
httpd -t -D DUMP_MODULES 查看是否安装成功
apreq_module (shared) 成功
LoadModule apreq_module modules/mod_apreq2.so
在httpd.conf 添加这个配置
7 在cpan中安装mason
install HTML::Mason
httpd.conf配置
PerlModule HTML::Mason::ApacheHandler
PerlSetVar MasonCompRoot "/var/www"
PerlSetVar MasonDataDir "/var/www"
<LocationMatch "\.(mhtml|mtxt|pl|html|shtml|)$">
SetHandler perl-script
PerlResponseHandler HTML::Mason::ApacheHandler
</LocationMatch>
mason使用方法 参考http://masonbook.houseabsolute.com/book/
8在cpan中安装minimvc
install MasonX::MiniMVC
文档说明http://search.cpan.org/~skud/MasonX-MiniMVC-0.03/lib/MasonX/MiniMVC.pm
注:此处最坑人,本人可能对linux系统不了解,在此卡了很长时间
运用mininmvc-install MyApp(项目名称)
项目目录必须为空
一定要现将此命令加入环境变量
export PATH=$PATH:/yang/www/bin(minimvc-install位置)
将配置文件改为
#<LocationMatch "\.(mhtml|mtxt|pl|html|shtml|)$">
<LocationMatch "">
SetHandler perl-script
PerlResponseHandler HTML::Mason::ApacheHandler
</LocationMatch>
9修改默认文件类型
#DefaultType text/plain
改为:DefaultType text/html
好了,你可以运用maosn的MVC模式了,请参考官方示例
注:以上根据自己电脑选择安装文件
说明:由于本人知识缺陷,可能导致存在很多不足,瑾此与大家交流学习,另,转载请注明出处。祝大家学习愉快