关于python:Apache 2.4无法在优胜美地上加载mod_wsgi.so

Apache 2.4 failing to load mod_wsgi.so on Yosemite

问题

使用OS X Yosemite和Python 2.7,我尝试使用Apache WSGI跟随Flask中的一个简单的hello世界,但是在执行apachectl -S时收到此错误:

1
httpd: Syntax error on line 171 of /private/etc/apache2/httpd.conf: Cannot load libexec/mod_wsgi.so into server: dlopen(/usr/libexec/mod_wsgi.so, 10): image not found

我尝试过的

首先,我将文件与其他mod_*文件放置在/usr/libexec/apache2/中。 其次,我尝试遵循Graham Dumpleton的回答并验证以下步骤:

1.您没有隐藏扩展名,并且已两次添加扩展名。

1
2
gwg$ file /usr/libexec/apache2/mod_wsgi.so
/usr/libexec/apache2/mod_wsgi.so: Mach-O 64-bit bundle x86_64

2.无论Apache服务用户是谁,都可以读取mod_wsgi.so文件。

我不确定确切如何执行此操作,但是我只是对照其他.so文件检查了该文件的权限。 例如:

1
2
gwg$ ls -l mod_vhost_alias.so
-rwxr-xr-x  1 root  wheel  19472 Sep  9 18:11 mod_vhost_alias.so

1
2
gwg$ ls -l mod_wsgi.so
-rwxr-xr-x  1 root  wheel  209564 Dec  4 17:05 mod_wsgi.so

3.您的Apache是32 [64]位。

1
I'm not sure how to do this.

4.您的Python是32 [64]位。

按照这样的答案:

1
2
3
>>> import struct
>>> print struct.calcsize("P") * 8
64

5.将为所有用户安装Python,而不仅仅是为您安装Python的用户。

1
2
3
4
5
6
gwg$ sudo su -
root# python
Python 2.7.6 (default, Sep  9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type"help","copyright","credits" or"license" for more information.
>>>

有什么帮助吗? 提前致谢。


对我而言,使用brew最容易在Mac OS X上运行wsgi
这是顺序。

  • brew tap homebrew/apache
  • brew install mod_wsgi
  • 必要时xcode-select --install
  • 您必须手动编辑/etc/apache2/httpd.conf以包含LoadModule wsgi_module /usr/local/Cellar/mod_wsgi/3.X/libexec/mod_wsgi.so

    • 截至2014年12月,X为5,但只需按照屏幕上显示的说明进行操作
  • 检查一切正常

    • httpd -t =>语法确定