我想在Max OS X 10.8.5中使用Apache和Perl进行CGI编程。我按照指南:CGI Programming With Apache and Perl on Mac OS X。步骤是:
AddHandler cgi-script .cgi .pl
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
Options MultiViews Indexes SymLinksIfOwnerMatch Includes ExecCGI
DirectoryIndex index.html index.cgi
AllowOverride None
Order allow,deny
Allow from all
sudo apachectl restart
sudo chmod 755 test.cgi
这就是我所做的一切。但是,当我访问:ht tp://localhost/~userName/test.cgi
时,结果:
Forbidden You don't have permission to access /~username/test.cgi on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
我尝试将一个html放入〜/ Sites,它可以正确显示。似乎cgi配置有问题,但我找不到它。有人可以给一些指南吗?
谢谢!
OSX Apache提供“两个”服务器。一个直接用于localhost,一个用于每个用户。在/ etc / apache2中查看用户目录的配置。有一个用户目录,该计算机上的每个OSX用户都有自己的配置:
<Directory "/Users/markus/Sites/">
Options Indexes MultiViews FollowSymLinks Includes ExecCGI
AllowOverride All
Allow from all
</Directory>
<VirtualHost *:80>
ServerName sencha
DocumentRoot "/Users/markus/Sites/sencha"
</VirtualHost>
还要确保在httpd.conf中启用了userprofiles
# User home directories
Include /private/etc/apache2/extra/httpd-userdir.conf
CGI Programming With Apache and Perl on Mac OS X中的步骤是正确的。如果重启apache不起作用,请重启mac!现在我可以使用cgi了!
以下步骤适用于High Sierra运行Apache 2.4
(基于以下优秀教程:http://www.cgi101.com/book/connect/mac.html,更新了版本差异的附加步骤)
1)将文件移动到:
/Library/WebServer/CGI-Executables
2)验证文件是否具有执行权限:
ls -l /Library/WebServer/CGI-Executables
如果不使用:
chmod -x /Library/WebServer/CGI-Executables/myfile.cgi
3)取消注释/etc/apache2/httpd.conf中的以下行
AddHandler cgi-script .cgi .pl
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
LoadModule cgi_module libexec/apache2/mod_cgi.so
4)还将目录“/ Library / WebServer / CGI-Executables”节更改为:
<Directory "/Library/WebServer/CGI-Executables">
AllowOverride None
Options ExecCGI
Require all granted
</Directory>
5)然后重启Apache:
sudo apachectl -k restart
几乎每个新的Mac OS版本,更改都将丢失,您将需要重做工作,甚至采取不同的步骤来解决它。你最好的朋友是/ var / log / apache2 /(/ var / log / apache2 / error_log)中的Apache日志