如何在apache服务器上运行cgi脚本 [英] How to run cgi script on apache server
问题描述
这是我的程序:
[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使用警告;使用警告;使用 CGI;打印内容类型:文本/html\n\n";print "<h2>Hello, World!</h2>\n";
我从我的浏览器调用脚本是这样的:
<块引用>This is my program:
[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:
I didn't get output, but I'm getting an error:
Not Found
The requested URL /usr/local/apache2/cgi-bin/first.pl was not found on this server.
Apache/2.2.15 (CentOS) Server at localhost Port 80
I checked in web browser whether the Apache web server is working or not by using :
It us showing the welcome page.
How do I resolve this error?
You basically need to change two files after installing apache2 on linux.
Go to terminal and set the following configs:
sudo vim /etc/apache2/sites-enabled/000-default.conf
and add the follwing:<Files ~ "\.(pl|cgi)$"> SetHandler perl-script PerlResponseHandler ModPerl::PerlRun Options +ExecCGI PerlSendHeader On </Files>
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>
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>
)
Finally, restart apache2: sudo apache2ctl restart
Screenshots:
这篇关于如何在apache服务器上运行cgi脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!