如何在apache服务器上运行cgi脚本 [英] How to run cgi script on apache server

查看:169
本文介绍了如何在apache服务器上运行cgi脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的程序:

[root@localhost cgi-bin]# locate first.pl 
/home/Ram/Desktop/work/first.pl
/usr/local/apache2/cgi-bin/first.pl
[root@localhost cgi-bin]# cd /usr/local/apache2/cgi-bin/
[root@localhost cgi-bin]# vi first.pl 
#!/usr/bin/perl -w
use warnings;
use warnings;
use CGI;
print "content-type: text/html\n\n";
print "<h2>Hello, World!</h2>\n";

我正在从浏览器中调用脚本,如下所示:

I am calling the script from my browser like this:

http://localhost/usr/local/apache2/cgi-bin/first.pl

我没有得到输出,但出现错误:

I didn't get output, but I'm getting an error:

未找到

在此服务器上找不到请求的URL/usr/local/apache2/cgi-bin/first.pl.

The requested URL /usr/local/apache2/cgi-bin/first.pl was not found on this server.

位于本地主机端口80上的Apache/2.2.15(CentOS)服务器

Apache/2.2.15 (CentOS) Server at localhost Port 80

我在Web浏览器中通过使用以下命令检查了Apache Web服务器是否正常工作:

I checked in web browser whether the Apache web server is working or not by using :

https://localhost

它显示欢迎页面.

如何解决此错误?

推荐答案

在Linux上安装apache2后,您基本上需要更改两个文件.

You basically need to change two files after installing apache2 on linux.

转到终端并设置以下配置:

Go to terminal and set the following configs:

  1. sudo vim /etc/apache2/sites-enabled/000-default.conf并添加以下内容:

<Files ~ "\.(pl|cgi)$">
    SetHandler perl-script
    PerlResponseHandler ModPerl::PerlRun
    Options +ExecCGI
    PerlSendHeader On
</Files>

  • sudo vim /etc/apache2/apache2.conf并添加以下内容:

  • sudo vim /etc/apache2/apache2.conf and add the following:

    <Directory /var/www/cgi-bin/> AddHandler cgi-script .cgi .pl Options FollowSymLinks ExecCGI AllowOverride None </Directory>

    <Directory /var/www/cgi-bin/> AddHandler cgi-script .cgi .pl Options FollowSymLinks ExecCGI AllowOverride None </Directory>

    添加这两个配置更改后,编写一个perl脚本,将其放在cgi-bin目录中,然后为其赋予足够的特权(sudo chmod 755 <filename>)

    After adding these two config changes, write a perl script, place it in the cgi-bin directory, and then give it sufficient privileges (sudo chmod 755 <filename>)

    最后,重新启动apache2:sudo apache2ctl restart

    Finally, restart apache2: sudo apache2ctl restart

    屏幕截图:

    这篇关于如何在apache服务器上运行cgi脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆