我有一个perl.cgi文件,其中包含以下内容:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<h1>Hello World</h1>\n";
Run Code Online (Sandbox Code Playgroud)
我让它可执行.(chmod a+x perl.cgi)
然后我perl.htm在同一目录中创建了一个新文件.其中包含以下数据:
Content-type: text/html
<p><a href="perl.cgi">RUN perl.cgi</a></p>
Run Code Online (Sandbox Code Playgroud)
当我perl.htm在浏览器中运行时,我得到的输出为:
Content-type: text/html
RUN perl.cgi
Run Code Online (Sandbox Code Playgroud)
当我点击RUN perl.cgi另一个页面打开时,输出为:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<h1>Hello World</h1>\n";
Run Code Online (Sandbox Code Playgroud)
即perl.cgi没有执行.仅显示文件内容.
编辑:从答案和评论我知道,我将不得不配置我的Web服务器(apache)来运行cgi脚本.我怎样才能做到这一点?让我知道.
Gab*_*oss 11
听起来Apache没有配置为运行*.cgi文件:
AddHandler cgi-script cgi pl
<Directory /path/to/cgi/files>
Options +ExecCGI
</Directory>
Run Code Online (Sandbox Code Playgroud)
确保在httpd.conf文件中加载CGI模块:
LoadModule cgi_module modules/mod_cgi.so或者
LoadModule cgi_module modules/mod_cgid.so取决于您运行的Apache版本.
您还可以阅读有关使用CGI的动态内容的其他解决方案 .