Apache2.x配置perl CGI心得

1 首先修改apache2的配置文件,打开/etc/apache2/apache2.conf,找到
#AddHandler cgi-script .cgi
一行,并改为
AddHandler cig-script .cgi .pl
2 安装libapache2-mod-perl2 软件包
3 安装好后可以对CGI脚本路径进行虚拟设置,如下面的设置:
ScriptAlias /cgi/ /home/shappen/perl/cgi-bin/

Options +ExecCGI
AddHandler cgi-script .cgi .pl


这样在浏览器中访问根目录下的cgi目录,便会重定向到/home/shappen/perl/cgi-bin/目录
4 至此安装成功,可以在cgi目录下放置测试文件进行测试(注意两个换行符):
cat test.pl
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "This is a test!";

chmod a+x test.pl
5 重启apache2 /etc/init.d/apache2 restart
访问 http://localhost/cgi/test.pl

相关推荐