2016-12-11 3 views
2

Ich versuche Python als CGI in Apache-Server ausführen. Python-Version ist 2.7.12. Hier ist meine Apache conf DateiAH01215: (8) Exec Format Fehler: Exec von '/var/www/python/hello.py' gescheitert: /var/www/python/hello.py

<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> 

Mein Python-Skript /var/www/python/hello.py wie dieses

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

sieht Wenn ich die URL ich den Internal Server Error erhalten Zugriff auf I habe die Details aus error.log Datei und es heißt,

[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-Skripts funktionieren immer noch gut auf dem Server. Wie behebt man dieses Problem mit Py-Dateien?

Antwort

4

Ihr Skript braucht einen "shebang" -Linie, so etwas wie

#!/usr/bin/env python 

als die erste Zeile. Stellen Sie außerdem sicher, dass das Skript mit chmod ausführbar ist.