AH01215:(8)执行格式错误:"/var/www/python/hello.py"的exec失败:/var/www/python/hello.py [英] AH01215: (8) Exec format error: exec of '/var/www/python/hello.py' failed: /var/www/python/hello.py

查看:57
本文介绍了AH01215:(8)执行格式错误:"/var/www/python/hello.py"的exec失败:/var/www/python/hello.py的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在apache服务器中将python作为CGI运行.Python版本是2.7.12.这是我的apache conf文件

I am trying to run python as CGI in apache server. Python version is 2.7.12. Here is my apache conf file

<VirtualHost *:80>
   <Directory /var/www/python>
   Options +ExecCGI
   AddHandler cgi-script .cgi .py
   Order allow,deny
   Allow from all
   </Directory>
   DocumentRoot /var/www/python
   ErrorLog ${APACHE_LOG_DIR}/error.log
   CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

我的python脚本/var/www/python/hello.py看起来像这样

My python script /var/www/python/hello.py looks like this

print('Content-Type: text/html; charset=utf-8\n')
print("Hello, World!")

访问url时,我收到内部服务器错误,我从error.log文件中获取了详细信息,并显示,

When I access the url I get the Internal Server Error, I got the details from error.log file and it says ,

[2016年12月11日星期日:09:53:40.694909] [cgi:error] [pid 6812] [client 127.0.0.1:36282]AH01215:(8)Exec格式错误:'/var/www/python/的exechello.py'失败:/var/www/python/hello.py[2016年12月11日,星期日,09:53:40.695312] [cgi:error] [pid 6812] [客户端127.0.0.1:36282]在标头之前的脚本输出结束:hello.py

[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文件解决此问题?

PHP scripts are still working fine on the server. How to fix this issue with py files ?

推荐答案

您的脚本需要一个"shebang"行,例如

Your script needs a "shebang" line, something like

#!/usr/bin/env python

作为第一行.另外,请确保脚本可以通过 chmod 执行.

as the first line. Also, make sure the script is executable with chmod.

这篇关于AH01215:(8)执行格式错误:"/var/www/python/hello.py"的exec失败:/var/www/python/hello.py的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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