I recently made a Mac Mini of M1 and planned to use it to develop MixPHP V3 version. I tried several times before but failed to compile it. Today, I tried again and succeeded in installing it.

Problems Facing

Because the latest version of MacOS Big Sur cannot write to files even when /usr/lib is turned off, make install cannot install any PHP extensions, so if you want to install Swoole, you have to compile and install PHP into /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

When compiling x64 Swoole, the exception is stopped. Instead, I have to look at ARM64 PHP+Swoole. When the exception is stopped, I have to look at ARM64 PHP+Swoole

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

The path in the parameter needs to be replaced according to the actual path installed on your computer

. / 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/[email protected]/1.1.1 k - with - iconv = / usr/local/make Cellar/libiconv / 1.16

PHP Build ERROR: No package 'openssl' found

You need to compile and install ARM64: openssl (LibreSSL is not allowed)

Based on the Mac Silicon M1 OpenSSL compiled: https://segmentfault.com/a/11…

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

–with-openssl = /usr/local/openssl = /usr/local/openssl

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

You need to compile and install 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

–with-iconv to /usr/local/libiconv

PHP Build ERROR: ld: warning: Ignoring the 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 needs to be compiled and installed

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

Required installation: Automake, can also be used with an x64

arch -x86_64 brew install automake

Continue compiling: oniguruma

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

Remove x64 oniguruma and attach ARM64 oniguruma to the system

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

PHP Build ERROR: ld: can't write output file: sapi/phpdbg/phpdbg for architecture arm64

sudo make && sudo make install

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

Ignore this exception

PHP Build ERROR: Allocation of JIT memory failed, PCRE JIT will be disabled. This is likely caused by security restrictions. Either grant PHP permission to allocate executable memory, or set pcre.jit=0

Sudo vim/Users / - 8.0.7 liujian/Downloads/PHP/ext/phar phar. PHP

New ini_set (” pcre. Jit “, “0”);

sudo make install

Swoole Build

Add a –enable-thread-context and specify –with-openssl-dir as the path to the compiled version

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 - the context  --with-openssl-dir=/usr/local/openssl make && sudo make install