升级 macos 10.15.3 后,开启PHP模块后,报错:
$ php -v
Failed loading /usr/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so: dlopen(/usr/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so, 0x0009): dlopen(): file not found: /usr/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so
PHP Warning: PHP Startup: Unable to load dynamic library '/Users/XXX/apps/mcrypt/mcrypt-1.0.0/modules/mcrypt.so' (tried: /Users/XXX/apps/mcrypt/mcrypt-1.0.0/modules/mcrypt.so (dlopen(/Users/XXX/apps/mcrypt/mcrypt-1.0.0/modules/mcrypt.so, 0x0009): code signature in (/Users/XXX/apps/mcrypt/mcrypt-1.0.0/modules/mcrypt.so) not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.), /usr/lib/php/extensions/no-debug-non-zts-20180731//Users/XXX/apps/mcrypt/mcrypt-1.0.0/modules/mcrypt.so.so (dlopen(/usr/lib/php/extensions/no-debug-non-zts-20180731//Users/XXX/apps/mcrypt/mcrypt-1.0.0/modules/mcrypt.so.so, 0x0009): dlopen(): file not found: /usr/lib/php/extensions/no-debug-non-zts-20180731//Users/XXX/apps/mcrypt/mcrypt-1.0.0/modules/mcrypt.so.so)) in Unknown on line 0
PHP 7.3.11 (cli) (built: Dec 13 2019 19:21:21) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies
第一个问题
$ ls -l /usr/lib/php/extensions/
total 0
drwxr-xr-x 4 root wheel 128 1 23 20:58 no-debug-non-zts-20180731
原来是目录变了,调整 /etc/php.ini 即可.
第二个问题
最初以为是系统升级,libmcrypt库没有了,安装试下
$ brew install mcrypt
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (exolnet/deprecated).
No changes to formulae.
Warning: mcrypt 2.6.8 is already installed and up-to-date
To reinstall 2.6.8, run `brew reinstall mcrypt`
仔细看了下刚才的错误,原来是“code signature”做怪,只有重新编译下mcrypt扩展了。
$ cd mcrypt-1.0.0
$ phpize
grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
autoconf: warning: both `configure.ac' and `configure.in' are present.
autoconf: warning: proceeding with `configure.ac'.
autoheader: 'configure.ac' and 'configure.in' both present.
autoheader: proceeding with 'configure.ac'
网查了下资料,一步步来:
$ cd /usr/
$ sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
Password:
ln: ./include: Operation not permitted
$ csrutil disable
csrutil: failed to modify system integrity configuration. This tool needs to be executed from the Recovery OS.
$ sudo mount -uw /
Password:
mount_apfs: volume could not be mounted: Operation not permitted
mount: / failed with 77
看吧,都不靠普,再试:
$ xcode-select --install
xcode-select: note: install requested for command line developer tools
运行 phpize 仍然报错"php.h"找不到。
我自认为自己是大牛,不管phpize错误,直接make:
mcrypt.c:25:10: fatal error: 'php.h' file not found
不就是头文件找不到吧,我加上还行么
echo $(xcrun --show-sdk-path)
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
export CFLAGS="-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/main -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/Zend -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/TSRM -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/ext -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php/sapi -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php"
----------------------------------------------------------------------
Libraries have been installed in:
/Users/XXX/apps/mcrypt/mcrypt-1.0.0/modules
网上一直半解的回答不少,如果只照做,而不自己思考,就会走进死胡同了。
最后,告诫大家,不是非不得已,macOS慎升级