Mac OSX:LoadModule wsgi_module无法按照文档

时间:2017-11-16 09:40:21

标签: python django apache mod-wsgi macos-sierra

由于Mac OSX中的安全原因,我将apache从2.4.25升级到2.4.29。 还通过pip安装了mod_wsgi。

现在在重启apache服务器时遇到困难!

我按照mod_wsgi docs

运行此命令
> mod_wsgi-express module-config
LoadModule wsgi_module "/Library/Python/2.7/site-packages/mod_wsgi/server/mod_wsgi-py27.so"
WSGIPythonHome "/System/Library/Frameworks/Python.framework/Versions/2.7"

复制apache.conf文件中的上述两行并尝试启动apache服务器,但收到以下错误:

> sudo apachectl start
/usr/local/apache/bin/apachectl: line 79: 51863 Illegal instruction: 4  $HTTPD -k $ARGV

任何帮助将不胜感激。谢谢!

根据格雷厄姆回答

编辑

# I upgraded the mod_wsgi
> sudo pip install --upgrade --no-cache-dir mod_wsgi
Collecting mod_wsgi
  Downloading mod_wsgi-4.5.21.tar.gz (2.5MB)
    100% |████████████████████████████████| 2.5MB 2.1MB/s 
Installing collected packages: mod-wsgi
  Found existing installation: mod-wsgi 4.5.20
    Uninstalling mod-wsgi-4.5.20:
      Successfully uninstalled mod-wsgi-4.5.20
  Running setup.py install for mod-wsgi ... done
Successfully installed mod-wsgi-4.5.21

但是当我尝试时:

> mod_wsgi-express start-server
Traceback (most recent call last):
  File "/Library/WebServer/Documents/DSFENV/bin/mod_wsgi-express", line 11, in <module>
    load_entry_point('mod-wsgi==4.5.21', 'console_scripts', 'mod_wsgi-express')()
  File "/Library/WebServer/Documents/DSFENV/lib/python2.7/site-packages/mod_wsgi/server/__init__.py", line 3484, in main
    cmd_start_server(args)
  File "/Library/WebServer/Documents/DSFENV/lib/python2.7/site-packages/mod_wsgi/server/__init__.py", line 3332, in cmd_start_server
    config = _cmd_setup_server('start-server', args, vars(options))
  File "/Library/WebServer/Documents/DSFENV/lib/python2.7/site-packages/mod_wsgi/server/__init__.py", line 2999, in _cmd_setup_server
    language, encoding = locale.getdefaultlocale()
  File "/Library/WebServer/Documents/DSFENV/lib/python2.7/locale.py", line 543, in getdefaultlocale
    return _parse_localename(localename)
  File "/Library/WebServer/Documents/DSFENV/lib/python2.7/locale.py", line 475, in _parse_localename
    raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8

得到上述错误。 此外,我在此blog之后安装了apache 2.4.29:

第二次修改 我已解决ValueError: unknown locale: UTF-8,现在mod_wsgi-express start-server的输出显示:

> mod_wsgi-express start-server
Server URL         : http://localhost:8000/
Server Root        : /tmp/mod_wsgi-localhost:8000:501
Server Conf        : /tmp/mod_wsgi-localhost:8000:501/httpd.conf
Error Log File     : /tmp/mod_wsgi-localhost:8000:501/error_log (warn)
Request Capacity   : 5 (1 process * 5 threads)
Request Timeout    : 60 (seconds)
Startup Timeout    : 15 (seconds)
Queue Backlog      : 100 (connections)
Queue Timeout      : 45 (seconds)
Server Capacity    : 20 (event/worker), 20 (prefork)
Server Backlog     : 500 (connections)
Locale Setting     : en_US.UTF-8

但是当我尝试进行配置测试时,仍然显示相同的错误:

> sudo apachectl configtest
/usr/local/apache/bin/apachectl: line 79: 53944 Illegal instruction: 4  $HTTPD -t

xcode版本:

> xcodebuild -version
Xcode 8.3.2
Build version 8E2002
根据评论

第3次编辑

> /usr/local/apache/bin/httpd
Illegal instruction: 4

> /Library/Python/2.7/site-packages/mod_wsgi/server/mod_wsgi-py27.so
-bash: /Library/Python/2.7/site-packages/mod_wsgi/server/mod_wsgi-py27.so: cannot execute binary file

> sys.prefix
'/System/Library/Frameworks/Python.framework/Versions/2.7'

> sys.version
'2.7.10 (default, Feb  7 2017, 00:08:15) \n[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)]'

我按照此博客安装Apache 2.4.29: http://mac-dev-env.patrickbougie.com/apache/
- with-ssl 选项,因为我们需要为网站https。

第四次编辑

> file /usr/local/apache/bin/httpd
/usr/local/apache/bin/httpd: Mach-O 64-bit executable x86_64

> file /Library/Python/2.7/site-packages/mod_wsgi/server/mod_wsgi-py27.so
/Library/Python/2.7/site-packages/mod_wsgi/server/mod_wsgi-py27.so: Mach-O universal binary with 2 architectures: [x86_64: Mach-O 64-bit bundle x86_64] [i386: Mach-O bundle i386]
/Library/Python/2.7/site-packages/mod_wsgi/server/mod_wsgi-py27.so (for architecture x86_64):   Mach-O 64-bit bundle x86_64
/Library/Python/2.7/site-packages/mod_wsgi/server/mod_wsgi-py27.so (for architecture i386): Mach-O bundle i386

请告诉我如何继续前进。

2 个答案:

答案 0 :(得分:1)

如果您以某种方式更新了Apache安装,通常旧版本的mod_wsgi.so二进制文件应该仍然可用,因为Apache在修补程序级别更新中保持ABI兼容性。

如果它不起作用,那么您可能需要重新构建mod_wsgi。如果没有较新版本的mod_wsgi,则需要强制完全重新构建以确保不使用来自pip缓存的缓存二进制文件。

pip install --upgrade --no-cache-dir mod_wsgi

接下来的问题是,如果你已经升级到Xcode 9.1,Apple会通过完全删除apxs来进一步破解,这意味着我之前对Apple破解的解决方法不再适用。在这种情况下,您需要确保安装mod_wsgi 4.5.21或更高版本。该版本刚刚发布,修复程序可以容纳Xcode 9.1

请尝试上面的pip命令并确保mod_wsgi-express仍可通过运行来运行:

mod_wsgi-express start-server

然后再次运行验证要在Apache配置中使用的配置代码段:

mod_wsgi-express module-config

如果仍然出现主Apache问题,那么请确保完全停止Apache然后启动,而不仅仅是重启。让我知道这一切是怎么回事。

更新1

以上假设您在Xcode 9.1评论中使用Apple提供的Apache。你似乎在使用你自己的Apache,也许是自制的。仍然尝试相同的事情。

答案 1 :(得分:0)

格雷厄姆建议:

pip install --upgrade --no-cache-dir mod_wsgi

升级到 mod_wsgi 4.5.22 就可以了。