配置Apache使用Python就像CGI PHP [英] Configure Apache to use Python just like CGI PHP

查看:180
本文介绍了配置Apache使用Python就像CGI PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想加入PHP到Apache网络服务器的一个俗称的办法是配置是这样的:

I think one commonly known way of adding PHP to an Apache webserver is to configure it like this:

ScriptAlias /php5.3 /usr/local/php5.3/bin
Action application/php5.3 /php5.3/php-cgi
AddType application/php5.3 .php

现在我试着写的Python类似的配置:

Now I tried to write a similar configuration for Python:

ScriptAlias /python /usr/bin
Action application/python /python/python
AddType application/python .py

我有一个小的测试脚本,看起来像这样:

I have a small test script that looks like this:

print "Content-Type: text/html\n\n"
print "Test"

但有些事情似乎是因为Apache错误日志错误说以下内容:

But something seems to be wrong since the apache error log says the following:

Premature end of script headers: python

所以,我的第一次,虽然是我的Python的反应是不正确的。但是,是Content-Type和也都换行。也被称为与 PHP-CGI 类似的PHP脚本的输出提供完全相同的输出。

So my first though was that my python response is not right. But there is the Content-Type and also both linebreaks. Also the output of a similar PHP script called with php-cgi gives exactly the same output.

另外,我还没有找到一个教程,显示如何让Python这种方式工作。所以也许这是不可能的,但我很好奇,为什么是这样的话?还是我失去了一些东西?

Also I haven't found a tutorial that shows how to get python working this way. So maybe it is not possible, but then I'm curious why this is the case? Or am I missing something?

推荐答案

所以,也许这是不可能的,但我很好奇,为什么是这样?

" So maybe it is not possible, but then I'm curious why this is the case?"

正确的。这是不可能的。从来就没有打算,要么。

Correct. It's not possible. It was never intended, either.

原因1 - Python是不是PHP。 PHP的 - 作为一个整体 - 期望成为一个CGI。 Python没有。

Reason 1 - Python is not PHP. PHP -- as a whole -- expects to be a CGI. Python does not.

原因2 - Python是不是天生一个CGI。这是一个跨preTER有(几乎)没有环保方面的需求。

Reason 2 - Python is not inherently a CGI. It's an interpreter that has (almost) no environmental expectations.

原因3 - Python的从来没有设计成一个CGI。这就是为什么Python的一般嵌入到小包装(mod_python的,mod_wsgi的,的mod_fastcgi),它可以在形式更有意义,正在运行的Python程序封装CGI环境。

Reason 3 - Python was never designed to be a CGI. That's why Python is generally embedded into small wrappers (mod_python, mod_wsgi, mod_fastcgi) which can encapsulate the CGI environment in a form that makes more sense to a running Python program.

这篇关于配置Apache使用Python就像CGI PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆