我试图在apache服务器中运行python作为CGI。Python版本是2.7.12。
这是我的apache conf文件
Options +ExecCGI
AddHandler cgi-script .cgi .py
Order allow,deny
Allow from all
DocumentRoot /var/www/python
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
我的python脚本/var/www/python/hello.py如下所示print('Content-Type: text/html; charset=utf-8\n')
print("Hello, World!")
当我访问url时,我得到了内部服务器错误,我从Error.log文件得到了详细信息,上面写着[Sun Dec 11 09:53:40.694909 2016] [cgi:error] [pid 6812] [client 127.0.0.1:36282] AH01215: (8)Exec format error: exec of '/var/www/python/hello.py' failed: /var/www/python/hello.py
[Sun Dec 11 09:53:40.695312 2016] [cgi:error] [pid 6812] [client 127.0.0.1:36282] End of script output before headers: hello.py
PHP脚本在服务器上仍然运行良好。
如何用py文件解决这个问题?