关于swoole:Mac-Silicon-M1-编译安装-PHP8-Swoole46-ARM64-全过程记录

45次阅读

共计 4364 个字符,预计需要花费 11 分钟才能阅读完成。

最近搞了一台 M1 的 Mac mini 筹备用这个开发 mixphp v3 版本,之前尝试了几次没有编译胜利,明天再次尝试装置胜利了,网络上很多人的文章存在问题(可能是零碎环境不同),特此分享让后续的人闭坑。

面临的问题

因为最新版本的 macOS Big Sur 即使敞开平安模式 /usr/lib 也无奈写入文件,因而导致 make install 无奈装置任何 php 扩大,因而想装 Swoole 只能自行编译装置 php 到 /usr/local 目录

% csrutil status
System Integrity Protection status: disabled.
% mkdir /usr/lib/php/extensions/test
mkdir: /usr/lib/php/extensions/test: Read-only file system

PHP Build

因为 brew arm64 版本无奈应用,只能采纳 x64 版本装置了一些依赖,前面导致了很多问题,本想编译一个 x64 PHP+Swoole 在编译 x64 Swoole 的时候异样就没有持续了,转而钻研 arm64 PHP+Swoole

arch -x86_64 brew install openssl zlib curl libjpeg libpng libxml2 gettext freetype pcre libiconv libzip

参数中的门路都须要依据本人电脑所装置的理论门路替换

./configure --prefix=/usr/local/php8.0.7 --with-config-file-path=/usr/local/php8.0.7/etc --with-config-file-scan-dir=/usr/local/php8.0.7/etc/php.d --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --with-mhash --enable-tokenizer --enable-pcntl --enable-sockets --enable-soap --enable-simplexml --without-pear --with-pear --with-zlib=/usr/local/opt/zlib --with-curl=/usr/local/Cellar/curl/7.77.0 --with-openssl=/usr/local/Cellar/openssl@1.1/1.1.1k --with-iconv=/usr/local/Cellar/libiconv/1.16
make

PHP Build ERROR: No package 'openssl' found

须要编译装置 arm64:openssl (零碎自带的 LibreSSL 不能够)

基于 Mac Silicon M1 的 OpenSSL 编译:https://segmentfault.com/a/11…

sudo cp /usr/local/openssl/lib/pkgconfig/* /usr/local/lib/pkgconfig/

持续编译:php (将 --with-openssl 更换为 /usr/local/openssl)

PHP Build ERROR: configure: error: Please reinstall the iconv library

须要编译装置 arm64:iconv

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar xvzf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make && sudo make install

持续编译:php (将 --with-iconv 更换为 /usr/local/libiconv)

PHP Build ERROR: ld: warning: ignoring file /usr/local/Cellar/oniguruma/6.9.7.1/lib/libonig.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64

须要编译装置 arm64:oniguruma

wget https://github.com/kkos/oniguruma/archive/v6.9.5_rev1.tar.gz
tar xvzf v6.9.5_rev1.tar.gz
cd oniguruma-6.9.5_rev1
./autogen.sh

Oniguruma Build ERROR: autoreconf: error: aclocal failed with exit status: 2

须要装置:automake,装置了一个 x64 的也能够用

arch -x86_64 brew install automake

持续编译:oniguruma

./autogen.sh
./configure --prefix=/usr/local/oniguruma
make && sudo make install

移除 x64 oniguruma 将 arm64 oniguruma 关联到零碎

arch -x86_64 brew uninstall oniguruma
sudo cp /usr/local/oniguruma/lib/pkgconfig/* /usr/local/lib/pkgconfig/
sudo cp /usr/local/oniguruma/include/* /usr/local/include/
export LDFLAGS="-L/usr/local/oniguruma/lib"
export CPPFLAGS="-I/usr/local/oniguruma/include"
export PKG_CONFIG_PATH="/usr/local/oniguruma/lib/pkgconfig"
make clean
./configure --prefix=/usr/local/php8.0.7 --with-config-file-path=/usr/local/php8.0.7/etc --with-config-file-scan-dir=/usr/local/php8.0.7/etc/php.d --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --with-mhash --enable-tokenizer --enable-pcntl --enable-sockets --enable-soap --enable-simplexml --without-pear --with-pear --with-zlib=/usr/local/opt/zlib --with-curl=/usr/local/Cellar/curl/7.77.0 --with-openssl=/usr/local/openssl --with-iconv=/usr/local/libiconv
make && sudo make install

PHP Build ERROR: PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.

减少 --disable-phar

./configure --prefix=/usr/local/php8.0.7 --with-config-file-path=/usr/local/php8.0.7/etc --with-config-file-scan-dir=/usr/local/php8.0.7/etc/php.d --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --with-mhash --enable-tokenizer --enable-pcntl --enable-sockets --enable-soap --enable-simplexml --without-pear --with-pear --disable-phar --with-zlib=/usr/local/opt/zlib --with-curl=/usr/local/Cellar/curl/7.77.0 --with-openssl=/usr/local/openssl --with-iconv=/usr/local/libiconv
sudo make clean && sudo make && sudo make install

Swoole Build

减少一个 --enable-thread-context,并指定 --with-openssl 为编译版本的门路

wget https://github.com/swoole/swoole-src/archive/refs/tags/v4.6.7.tar.gz
tar xvzf v4.6.7.tar.gz
cd swoole-src-4.6.7
./configure --with-php-config=/usr/local/php8.0.7/bin/php-config --enable-openssl --enable-http2 --enable-thread-context --with-openssl-dir=/usr/local/openssl
make && sudo make install

正文完
 0