我正在尝试将Python设置为在mac上运行本地apache服务器。
在httpd.conf上,我
<VirtualHost *:80>
DocumentRoot "/Users/ptamzz/Sites/python/sandbox.ptamzz.com"
<Directory "/Users/pritams/Sites/python/sandbox.ptamzz.com">
Options Indexes FollowSymLinks MultiViews ExecCGI
AddHandler cgi-script .py
Require all granted
</Directory>
DirectoryIndex index.py
ServerName sandbox.ptamzz.com
ErrorLog "/var/log/apache2/error-log"
CustomLog "/var/log/apache2/access-log" common
</VirtualHost>在我的文档根目录中,我的index.py文件作为
#!/usr/bin/python
print "Content-type: text/html"
print "<html><body>Pritam's Page</body></html>"但是,当我在浏览器上加载页面时,python代码将按原样返回。

我错过了什么?
发布于 2015-04-19 10:37:01
在Apache ( cgi )中执行python
系统: OSX yosmite 10.10.3,默认apache
配置中未注释的
LoadModule cgi_module libexec/apache2/mod_cgi.so虚拟主机条目
<VirtualHost *:80>
# Hook virtual host domain name into physical location.
ServerName python.localhost
DocumentRoot "/Users/sj/Sites/python"
# Log errors to a custom log file.
ErrorLog "/private/var/log/apache2/pythonlocal.log"
# Add python file extensions as CGI script handlers.
AddHandler cgi-script .py
# Be sure to add ** ExecCGI ** as an option in the document
# directory so Apache has permissions to run CGI scripts.
<Directory "/Users/sj/Sites/python">
Options Indexes MultiViews FollowSymLinks ExecCGI
AddHandler cgi-script .cgi
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>index.py文件
#!/usr/bin/env python
print "Content-type: text/html"
print
print "<html><body>Test Page</body></html>"文件可执行使用
chmod a+x index.py重新启动apache并输出

发布于 2020-05-15 16:45:16
对于Apache (2.4)的以后版本,Sojan V Jose的答案主要还是适用的,只是我的授权失败了,可以通过替换:
Order allow,deny
Allow from all通过以下方式:
Require all grantedhttps://stackoverflow.com/questions/29723590
复制相似问题