Ubhuntu下安装配置Apache2 Perl cgi-bin

首先安装sudo apt-get install libperl-dev

http://httpd.apache.org/download.cgi#apache22下载httpd

安装方法:./configure  make  make install

这样你的apache2就安装到了/usr/local/apache2下.

cd /usr/local/apache2/bin

sudo ./apachectl start

在地址栏输入127.0.0.1,发现“It works!",页面的内家取决于htdocs/index.html的内容。

任何地方都可以调用apachectl

sudo vim /root/.bashrc

export PATH="$PATH:/usr/local/apache2/bin"

vim ~/.bashrc

export PATH="$PATH:/usr/local/apache2/bin"

设置开机自动启动Apache

在/etc/init.d下建立一个shell文件apache

#!/bin/bash
/usr/local/apache2/bin/apachectl start

$chmod +x apache

在/etc/rc5.d下建立一个指向apache的软链接

$ln -s /etc/init.d/apache S20apache

因为rc(0--6,S).d下的文件是在系统启动后自动执行的嘛,另外rc(0--6,S).d下文件名的命名规则:以S开头是启动,以K开关不是启动。注意rc.d下建立的软件链接指向的文件必须是/etc/init.d下的文件。

最后执行update-rc.d apache defaults

详细内容参加rc5.d下面的README文件。

实际上开机自动启动还有另外一种简单的方式:System==>Preference==>Startup Applications

在/usr/local/apache2/cgi-bin下已经给了个测试程序test-cgi,我们在地址栏是输入127.0.0.1/cgi-bin/test-cgi发现“Internal Server Error",出现这个问题有三种原因:

  1. 找不到脚本解释器。shell的话第一行就用#!/bin/sh,Perl的话第一行就用#!/usr/bin/perl
  2. 脚本语法有误
  3. 权限问题。从浏览器中访问apache服务器文件的用户默认组别是"Nobody",执行sudo chmod 755 test-cgi就解决问题了。

sudo chmod 777 /usr/local/apache2/cgi-bin

在cgi-bin下新建一个文件hello.pl

#!/usr/bin/perl
print "Content-type: text/html";
print "Hello, World.";

$chmod 755 hello.pl

在浏览器地址栏输入http://localhost/cgi-bin/hello.pl测验一下。

下面给一个正式的CGI代码,也是我做的第一个搜索引擎的demo,具有划时代的意义!

?
#!/usr/bin/perl
use CGI qw(:standard);
use Search::Xapian;
print header;
print start_html(-title=> 'ISee Search Engine' ,-align=> 'center' );
print start_form,
     textfield( 'terms' ),
     submit( 'Search' ),
     p,
     end_form;
print hr;
if (param()){
     my $db = Search::Xapian::Database->new( "/home/orisun/master/db2" );
     my $term =param( 'terms' );
     my $enq = $db ->enquire( $term );
     ##printf "Running query '%s'\n", $enq->get_query()->get_description();
     my @matches = $enq ->matches(0, 10);
     print scalar ( @matches ) . " results found" ;
     print br;
     foreach my $match ( @matches ) {
         my $doc = $match ->get_document();
         printf "ID=%d Percent=%d%%<br>%s" , $match ->get_docid(), $match ->get_percent(), $doc ->get_data();
         print p;
     }
}
print end_html;

运行效果:

 
 
彻底删除Apache
首先停止服务:
service httpd stop
apchectl stop
再删除
1、sudo apt-get  --purge remove apache2
2、sudo apt-get --purge remove apache2.2-common
3、sudo apt-get autoremove (此命令会自动卸载PHP)
最后手动删除Apache的所有文件

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值