Cyrus Blog

FLAG{S0_H4PPY_C_U_H3R3} (>.<)

解决MacOS自带Apache Incompatible library version 报错

本文共 451 字,预计阅读时间 2 分钟。

解决范围

报错

各种原因为 Incompatible library version 的报错

PHP版本

7.x
可适用于任何相关报错

macOS版本

macOS High Sierra, 10.13.4 (17E199)
经测试可适用于 10.12
通常 10.14 没有这个报错问题,如遇到请谨慎解决

解决方案

brew install -s php70
sudo apachectl configtest 显示 Syntax OK 的情况下可以忽略编号为 AH00558 的关于 ServerName 的报错。

问题详情

通过 Homebrew 以 brew install php70 类似方式安装了多个版本 PHP。
典型主要报错信息为:Incompatible library version: libphp7.so requires version 7.0.0 or later, but libaprutil-1.0.dylib provides version 4.0.0
典型全部报错如下:

1
2
$ sudo apachectl -k restart
httpd: Syntax error on line 183 of /private/etc/apache2/httpd.conf: Cannot load /usr/local/Cellar/[email protected]/7.0.32/lib/httpd/modules/libphp7.so into server: dlopen(/usr/local/Cellar/[email protected]/7.0.32/lib/httpd/modules/libphp7.so, 10): Library not loaded: /usr/local/opt/apr-util/libexec/lib/libaprutil-1.0.dylib\n Referenced from: /usr/local/Cellar/[email protected]/7.0.32/lib/httpd/modules/libphp7.so\n Reason: Incompatible library version: libphp7.so requires version 7.0.0 or later, but libaprutil-1.0.dylib provides version 4.0.0

解决详情

经过尝试各种添加 --with-xxx 之类的操作不能解决问题。
参考 homebrew-php Issue#763,使用 brew install -s php70 从源码安装,可以覆盖原来 macOS 自带的 Apache。
前后比对如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14

# 覆盖前
$ which apachectl
/usr/sbin/apachectl
$ apachectl -v
Server version: Apache/2.4.29 (Unix)
Server built: Jan 17 2018 18:20:31

# 覆盖后
$ which apachectl
/usr/local/bin/apachectl
$ apachectl -v
Server version: Apache/2.4.35 (Unix)
Server built: Sep 24 2018 01:07:08

在运行 configtest 的时候会有一个报错,但是可以运行。报错如下:

1
2
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using CryusMBA.local. Set the 'ServerName' directive globally to suppress this message
Syntax OK

出现编号为 AH00091 的权限问题请自行 sudo 解决。