Python web脚本不能在apache上运行

时间:2014-07-22 18:18:49

标签: python linux apache cgi

我正在尝试开始使用python web编程,但我遇到了问题。我想和CGI合作 我在pc(Linux)上安装了Ampps web-server。根据这条指示Apache Tutorial: Dynamic Content with CGI。我将文件index.pl放在文件夹' / usr / local / ampps / www / cgi-bin'并试图访问它

http://localhost/cgi-bin/index.py 

以下是我的档案代码:

#!/usr/local/ampps/python/bin/python
print "Content-type: text/html\n\n" 
print "Hello World from PythonStandard Hello World from a Python"

但它给了我错误抱歉,您要查找的页面目前无法使用。

以下是Apache的错误日志:

[Tue Jul 22 20:05:45.019799 2014] [cgi:error] [pid 11952] [client 127.0.0.1:38359] AH01215:(13)权限被拒绝:执行' / usr / local / ampps /网络/的cgi-bin / index.py'失败 [Tue Jul 22 20:05:45.020262 2014] [cgi:error] [pid 11952] [client 127.0.0.1:38359]标题前的脚本输出结束:index.py

我更正了Apache的内容

AddHandler cgi-script .cgi .pl .py

看起来也不错

LoadModule cgi_module modules/mod_cgi.so
ScriptAlias /cgi-bin/ "{$path}/www/cgi-bin/"

其他可能有什么不妥?

2 个答案:

答案 0 :(得分:1)

您的脚本需要设置可执行位(使用chmod)和Apache用户或组(通常命名为' Apache'或者' www-data'取决于你的发行版 - 你可以查看/ etc / passwd来查找)必须有'执行'许可。

答案 1 :(得分:0)

我遇到了类似的错误。似乎Python的AMPPS安装缺少其中一个DLL。我从ActiveState下载了2.7 .msi包并安装了它。

开始之前的一些事情:位置和权限。

我可能错了,但是Apache会在AMPPS安装中为它创建的目录中寻找Python可执行文件--c:\ whatever \ whatever \ ampps \ python。我尝试在c:\ whatever \ whatever \ ampps \ python2.7中安装它,但它没有用。我想我可以编辑httpd.conf文件,但由于最初的安装无法正常工作,我覆盖了c:\ w \ w \ ampps \ python文件。

我还以管理员身份运行.msi。这很棘手,因为我公司发行的机器不允许我只是右键单击.msi并选择“以管理员身份运行”。我终于进入了任务管理器(这里的选项8:http://www.eightforums.com/tutorials/9564-run-administrator-windows-8-a.html),并在条目中放置了下载文件的完整路径。瞧,“你好世界。”

相关问题