我正在尝试创建一个 python 脚本 (widget.py),它将从任意资源获取 JSON 提要。我无法让 python 脚本在本地主机上执行。以下是我遵循的步骤:
- 在
etc/apache2/httpd.conf我启用了LoadModule cgi_module libexec/apache2/mod_cgi.so - 重新启动 Apache
sudo apachectl restart 在我的目录中添加了一个 .htaccess 文件:
<Directory "widget.py"> Options +ExecCGI AddHandler cgi-script .py </Directory>注意:我最终需要将其部署在无法访问 apache2 目录的服务器上。
导航到
http://localhost/~walter/widget/widget.py
我收到 500 服务器错误。日志文件内容:
[Sat Jul 01 08:51:00.922413 2017] [core:info] [pid 75403] AH00096: removed PID file /private/var/run/httpd.pid (pid=75403) [Sat Jul 01 08:51:00.922446 2017] [mpm_prefork:notice] [pid 75403] AH00169: caught SIGTERM, shutting down AH00112: Warning: DocumentRoot [/usr/docs/dummy-host.example.com] does not exist AH00112: Warning: DocumentRoot [/usr/docs/dummy-host2.example.com] does not exist [Sat Jul 01 08:51:01.449227 2017] [mpm_prefork:notice] [pid 75688] AH00163: Apache/2.4.25 (Unix) PHP/5.6.30 configured -- resuming normal operations [Sat Jul 01 08:51:01.449309 2017] [core:notice] [pid 75688] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
我需要在 /etc/apache2/users/walter/http.conf 中启用 cgi 吗? ?我应该吗?
请您参考如下方法:
开始工作了。以下是我遵循的步骤:
在
etc/apache2/httpd.conf中我取消了注释:LoadModule cgi_module libexec/apache2/mod_cgi.so重新启动 Apache
sudo apachectl restart列表项在我的目录中添加了一个 .htaccess 文件,内容如下:
选项 ExecCGI AddHandler cgi 脚本 .py 订单允许、拒绝 允许所有将
#!/usr/bin/env python添加到我的 python 脚本的顶部- 在终端中使用以下命令启用 python 脚本的执行:
chmod +x widget.py
