背景
网上很多教程基于macos intel芯片的,目前m1芯片网上几乎没有
我打开命令行窗口,执行一条命令
php -v
得到的输出是
WARNING: PHP is not recommended
PHP is included in macOS for compatibility with legacy software.
Future versions of macOS will not include PHP.
PHP 7.3.24-(to be removed in future macOS) (cli) (built: Nov 23 2020 06:45:16) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.24, Copyright (c) 1998-2018 Zend Technologies
PS:如果没有安装brew 参考我的 brew 安装教程
意思是说本身就带了php7.3,未来的版本可能会去掉,此时我执行命令
安装
安装PHP7.4
brew install php@7.4
为了覆盖本地PHP 环境信息(这里的7.4.20 是我安装的版本 )
Version=$(ls -al /opt/homebrew/Cellar/php@7.4/ | awk '{print $9}' | grep 7.4)
echo "PATH=/opt/homebrew/Cellar/php@7.4/$Version/bin:/opt/homebrew/Cellar/php@7.4/$Version/sbin:$PATH" >> ~/.zshrc
source ~/.zshrc
php -v # 信息应为 php7.4.20
启动
brew services start php@7.4
安装依赖(M1特有)
安装YAF
sudo pecl install yaf
遇到问题查看下面报错fatal error: ‘pcre2.h’
报错fatal error: ‘pcre2.h’
## 例子
In file included from /private/tmp/pear/temp/swoole/ext-src/php_swoole.cc:21:
/usr/local/Cellar/php/8.0.0_1/include/php/ext/pcre/php_pcre.h:23:10: fatal error: 'pcre2.h' file not found
#include "pcre2.h"
^~~~~~~~~
1 error generated.
make: *** [ext-src/php_swoole.lo] Error 1
ERROR: `make' failed
这块一直error 原因你本地没有对应的引用 需要你本地进行一下软连接
新版本M1芯片 在/opt/homebrew地方
1.递归创建目录
mkdir -p /opt/homebrew/Cellar/php@7.4/7.4.20/include/php/ext/pcre/
2.软连接操作
ln -s /opt/homebrew/Cellar/pcre2/10.37/include/pcre2.h /opt/homebrew/Cellar/php@7.4/7.4.20/include/php/ext/pcre/pcre2.h
PS:后续使用会警告
老PHP程序员告诉我不用管,可以忽略
PHP Warning: PHP Startup: Unable to load dynamic library 'yaf.so' (tried: /opt/homebrew/lib/php/pecl/20190902/yaf.so (dlopen(/opt/homebrew/lib/php/pecl/20190902/yaf.so, 9): no suitable image found. Did find:
/opt/homebrew/lib/php/pecl/20190902/yaf.so: mach-o, but wrong architecture
/opt/homebrew/lib/php/pecl/20190902/yaf.so: stat() failed with errno=22), /opt/homebrew/lib/php/pecl/20190902/yaf.so.so (dlopen(/opt/homebrew/lib/php/pecl/20190902/yaf.so.so, 9): image not found)) in Unknown on line 0
Warning: PHP Startup: Unable to load dynamic library 'yaf.so' (tried: /opt/homebrew/lib/php/pecl/20190902/yaf.so (dlopen(/opt/homebrew/lib/php/pecl/20190902/yaf.so, 9): no suitable image found. Did find:
/opt/homebrew/lib/php/pecl/20190902/yaf.so: mach-o, but wrong architecture
/opt/homebrew/lib/php/pecl/20190902/yaf.so: stat() failed with errno=22), /opt/homebrew/lib/php/pecl/20190902/yaf.so.so (dlopen(/opt/homebrew/lib/php/pecl/20190902/yaf.so.so, 9): image not found)) in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'swoole.so' (tried: /opt/homebrew/lib/php/pecl/20190902/swoole.so (dlopen(/opt/homebrew/lib/php/pecl/20190902/swoole.so, 9): no suitable image found. Did find:
/opt/homebrew/lib/php/pecl/20190902/swoole.so: mach-o, but wrong architecture
/opt/homebrew/lib/php/pecl/20190902/swoole.so: mach-o, but wrong architecture), /opt/homebrew/lib/php/pecl/20190902/swoole.so.so (dlopen(/opt/homebrew/lib/php/pecl/20190902/swoole.so.so, 9): image not found)) in Unknown on line 0
Warning: PHP Startup: Unable to load dynamic library 'swoole.so' (tried: /opt/homebrew/lib/php/pecl/20190902/swoole.so (dlopen(/opt/homebrew/lib/php/pecl/20190902/swoole.so, 9): no suitable image found. Did find:
/opt/homebrew/lib/php/pecl/20190902/swoole.so: mach-o, but wrong architecture
/opt/homebrew/lib/php/pecl/20190902/swoole.so: mach-o, but wrong architecture), /opt/homebrew/lib/php/pecl/20190902/swoole.so.so (dlopen(/opt/homebrew/lib/php/pecl/20190902/swoole.so.so, 9): image not found)) in Unknown on line 0
PHP 7.4.20 (cli) (built: Jun 3 2021 19:10:14) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.20, Copyright (c), by Zend Technologies
参考:
https://github.com/swoole/swoole-src/issues/3926
https://blog.csdn.net/silk_java/article/details/111769920