Exec format error: apache + mod_wsgi on Mac OS X Lion

I am trying to set up a web development environment using Python 2.7, apache, mod_wsgi and web2py on an iMac running Lion (Mac OS X 10.7.3).

I downloaded and installed mod_wsgi v. 3.3 (./configure; make; sudo make install)

It is installed in / usr / libexec / apache 2. Everything looks reasonable:

07:49 PM ~ [541] otool -L /usr/libexec/apache2/mod_wsgi.so /usr/libexec/apache2/mod_wsgi.so: /Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0) /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 635.19.0) 07:55 PM ~ [542] file /usr/libexec/apache2/mod_wsgi.so /usr/libexec/apache2/mod_wsgi.so: Mach-O universal binary with 2 architectures /usr/libexec/apache2/mod_wsgi.so (for architecture x86_64): Mach-O 64-bit bundle x86_64 /usr/libexec/apache2/mod_wsgi.so (for architecture i386): Mach-O bundle i386 

I added some configuration directives to / private / etc / apache 2 / httpd.conf after all the LoadModule directives.

 LoadModule wsgi_module libexec/apache2/mod_wsgi.so WSGIScriptAlias / /Library/WebServer/Documents 

I restarted the apache daemon. The apache log looked pretty good:

[Thu Feb 09 19:19:15 2012] [notification] Apache / 2.2.21 (Unix) mod_ssl / 2.2.21 OpenSSL / 0.9.8r DAV / 2 mod_wsgi / 3.3 Configuring Python / 2.7.2 - resuming normal operations

I put this file in the / Library / WebServer / Documents folder:

 def application(environ, start_response): status = '200 OK' output = 'Hello World!' response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output] 

I executed it from my browser using http://192.168.1.2/test.py

I got the answer "Internal server 500 error."

My server log says:

 [Thu Feb 09 20:12:10 2012] [error] [client 192.168.1.2] (8)Exec format error: exec of '/Library/WebServer/Documents/test.py' failed [Thu Feb 09 20:12:10 2012] [error] [client 192.168.1.2] Premature end of script headers: test.py [Thu Feb 09 20:12:10 2012] [error][client 192.168.1.2] mod_wsgi (pid=4251): Target WSGI script '/Library/WebServer/Documents/favicon.ico' does not contain WSGI application 'application'. 

After a long search, I could not find out why. I even ran favicon.ico in the docs folder. This made it log:

 [Thu Feb 09 19:15:44 2012] [error] [client 192.168.1.2] (8)Exec format error: exec of '/Library/WebServer/Documents/test.py' failed [Thu Feb 09 19:15:44 2012] [error] [client 192.168.1.2] Premature end of script headers: test.py [Thu Feb 09 19:15:46 2012] [error] [client 192.168.1.2] mod_wsgi (pid=4135): Target WSGI script '/Library/WebServer/Documents/favicon.ico' does not contain WSGI application 'application'. 

Any help would be appreciated.

+4
source share
1 answer

You have mapped WSGIScriptAlias ​​to the DocumentRoot directory itself and without a slash in the directory, which probably means that it is trying to load the directory in some way as a WSGI script file and does not work. The premature end of the script message file is confusing, though if you haven't included all your mod_wsgi configuration. This message indicates that you are using the mod_wsgi daemon mode, which is not displayed, or that something is actually interpreted as a CGI script.

In any case, what you probably want to do if you want to delete .py files in DocumentRoot is to remove WSGIScriptAlias, and then add:

 <Directory /Library/WebServer/Documents> AddHandler wsgi-script .py Options +ExecCGI </Directory> 

This will mean that "http://192.168.1.2/test.py" should work, plus you can put other static files in this directory and they will be served.

Make sure you proceed to review:

http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide

+1
source

Source: https://habr.com/ru/post/1395716/


All Articles