我刚刚从Python开始。 Python解释器是从命令行工作的(我有2.4.3),但我似乎无法让Apache执行Python脚本。 所有我最终都是一个空白的屏幕,没有在Apache错误日志。
我通过Plesk控制面板启用了Python。 这是httpd.include中生成的片段:
<Files ~ (\.py$)> SetHandler python-program PythonHandler mod_python.cgihandler </Files>
我的testing脚本是http://python.org/download/上的Python下载的例子之一
#!/usr/local/bin/python """CGI test 1 - check server setup.""" # Until you get this to work, your web server isn't set up right or # your Python isn't set up right. # If cgi0.sh works but cgi1.py doesn't, check the #! line and the file # permissions. The docs for the cgi.py module have debugging tips. print("Content-type: text/html") print() print("<h1>Hello world</h1>") print("<p>This is cgi1.py")
这是行不通的,所以我把#!/usr/local/bin/python改成#!/usr/local/bin/python #!/usr/bin/python ,这是which python告诉我的,但结果是一样的。
就像我说过的,我只是空白页面而已。 没有错误,我知道,除非我检查错误的日志(我正在检查Apache错误日志)。 我正在运行CentOS的MediaTemple(dv)。
尝试通过replace代码:
print("Content-type: text/html") print()
至
print("Content-type: text/html") print("\n\n")
编辑
如果从terminal运行, print() =>将打印()
print =>将打印换行符“\ n”。 在这里查看文档(查找打印)
A.)确保你可以从命令行运行你的脚本。 B.)尝试在第一次打印()后添加一个额外的print()。