[分享]win2k pro+apache執行CGI的方法



贊助商連結


噩夢
2001-11-18, 02:06 PM
一、先去 ActiveState (http://www.activestate.com/Products/ActivePerl/download.plex) 下載perl安裝套件

二、編輯apache\conf\httpd.conf這個檔案

三、找到 #AddModule mod_include.c mod_autoindex.c mod_dir.c mod_cgi.c mod_userdir.c
將前面的#去掉

四、找到 #!/usr/bin/perl 將他改成改成你的perl安裝目錄,例如 #!e:/perl/bin/perl.exe

五、找到
#
# "G:/Apache/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "E:/www/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
改成
#
# "G:/Apache/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "E:/www/cgi-bin">
AllowOverride None
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>

如果要讓別的使用者使用,只要在這段下面加上
<Directory "E:/www/nightmare/cgi-bin">
AllowOverride None
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>
E:/www/nightmare/cgi-bin是其他使用者的cgi-bin目錄
記得要放在</IfModule>這行的前面

六、找到這段
# AddHandler allows you to map certain file extensions to "handlers",
# actions unrelated to filetype. These can be either built into the server
# or added with the Action command (see below)
#
# If you want to use server side includes, or CGI outside
# ScriptAliased directories, uncomment the following lines.
#
# To use CGI scripts:
#
將 #AddHandler cgi-script .cgi 前面的#去掉並改成 AddHandler cgi-script .pl .cgi

七、將你要執行的perl檔案,例如安裝完ActiveState後有個printenv.pl,內容是
#!/usr/local/bin/perl
##
## printenv -- demo CGI program which just prints its environment
##

print "Content-type: text/plain\n\n";
foreach $var (sort(keys(%ENV))) {
$val = $ENV{$var};
$val =~ s|\n|\\n|g;
$val =~ s|"|\\"|g;
print "${var}=\"${val}\"\n";
}
將第一行改成你放perl.exe的位置,例如本範例中我的perl.exe位置是e:/perl/bin/perl.exe
那就要改成
#!e:\perl\bin\perl.exe

八、重新啟動apache

九、完成...打入你自己的網址,例如http://localhost/cgi-bin/printenv.pl去測試看看吧..:D :D :D

我用過cgi,perl,apache在PCZONE上搜尋過,都沒找到類似的文章...
如果有重複發表,還請大家多多見諒...:p
我是Apache的新手,如果這篇發表有任何需要改正的地方或是有更高階的方法,還請各位前輩多多發表自己的意見

贊助商連結


C.K.
2002-03-07, 12:28 PM
那有沒有win2k service + iis5.0執行CGI的方法呢
看了個大論壇及討論區
好像都沒有這類的討論及教學
而這一個網站
ActiveState下載的地方卻寫
Windows 2000, XP: No additional requirements
是不是w2k+iis5.0沒法跑cgi
一定要linux才可以
還是有內建了
那麼執行路徑呢~