關於apache與CGI在這裡就不解釋了.
1、apache下載地址:http://www.apache.org,下面以2.0.63為例介紹運行CGI程式的配置。
2、下載Windows下的Perl解譯器ActivePerl,官方網站:http://www.activestate.com/,最新版本ActivePerl- 5.10.0.1003,假設安裝路徑為c:Perl。
3、修改apache的設定檔httpd.conf:
代碼如下 |
複製代碼 |
<Directory "D:/Apache Group/Apache2/cgi-bin"> AllowOverride None Options None Order allow,deny Allow from all </Directory> #AddHandler cgi-script .cgi 改為: <Directory "D:/Apache Group/Apache2/cgi-bin"> AllowOverride None Options ExecCGI Order allow,deny Allow from all </Directory> AddHandler cgi-script .cgi .pl |
4、編寫perl指令碼程式hello.pl
代碼如下 |
複製代碼 |
#!C:Perlbinperl.exe print "content-type: text/html","nn"; print "<HTML>","n"; print "<HEAD>","n"; print "<TITLE>Perl</TITLE>","n"; print "</HEAD>","n"; print "<BODY>","n"; print "<H1>Hello World</H1>","n"; print "</BODY>","n"; print "</HTML>","n"; |
將程式拷貝到apache安裝目錄下cgi-bin檔案夾下.
5、啟動apache伺服器,開啟瀏覽器,輸入http://localhost/cgi-bin/hello.pl