[英]AH01215: (8) Exec format error: exec of '/var/www/python/hello.py' failed: /var/www/python/hello.py
I am trying to run python as CGI in apache server. 我试图在Apache服务器上运行python作为CGI。 Python version is 2.7.12.
Python版本是2.7.12。 Here is my apache conf file
这是我的apache conf文件
<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>
My python script /var/www/python/hello.py looks like this 我的python脚本/var/www/python/hello.py看起来像这样
print('Content-Type: text/html; charset=utf-8\n')
print("Hello, World!")
When I access the url I get the Internal Server Error, I got the details from error.log file and it says , 当我访问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
[Sun Dec 11 09:53:40.694909 2016] [cgi:error] [pid 6812] [client 127.0.0.1:36282] AH01215:(8)exec格式错误:'/var/www/python/hello.py的exec '失败:/var/www/python/hello.py [Sun Dec 11 09:53:40.695312 2016] [cgi:error] [pid 6812] [client 127.0.0.1:36282]标题前面的脚本输出结束:hello。 PY
PHP scripts are still working fine on the server. PHP脚本在服务器上仍然可以正常工作。 How to fix this issue with py files ?
如何解决py文件的这个问题?
Your script needs a "shebang" line, something like 你的脚本需要一个“shebang”行,类似于
#!/usr/bin/env python
as the first line. 作为第一线。 Also, make sure the script is executable with
chmod
. 另外,请确保脚本可以使用
chmod
。
You should use: 你应该使用:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
print('Content-Type: text/html; charset=utf-8\n')
print("ąęśłłłóąś UTF answer")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.