macos 本地安装 swoole

8/18/2023 php

# 安装 php7.4

brew install shivammathur/php/php@7.4
1

# 注入环境变量

cat > ~/.zshrc <<EOF
export PATH="/opt/homebrew/opt/php@7.4/bin:$PATH"
export PATH="/opt/homebrew/opt/php@7.4/sbin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/php@7.4/lib"
export CPPFLAGS="-I/opt/homebrew/opt/php@7.4/include"
EOF 
1
2
3
4
5
6

# 安装 composer

wget https://mirrors.ustc.edu.cn/homebrew-bottles/composer-2.5.8.arm64_ventura.bottle.tar.gz
tar xzvf composer-2.5.8.arm64_ventura.bottle.tar.gz cp composer/2.5.8/bin/composer /opt/homebrew/bin
1
2

# 安装 swoole

下载源码并解压

curl -L -O https://pecl.php.net/get/swoole-4.8.13.tgz
tar xzvf swoole-4.8.13.tgz
cd swoole-4.8.13
1
2
3

编译安装 swoole

phpize && \ 
./configure \
	--enable-openssl \
	--enable-sockets \
	--enable-mysqlnd \
	--enable-swoole-curl \
	--enable-http2 \
	--with-openssl-dir=/opt/homebrew/Cellar/openssl@3/3.0.8
make && make install
1
2
3
4
5
6
7
8
9

解决 swoole 无法找到 pcre2.h

ln -s /opt/homebrew/Cellar/pcre2/10.42/include/pcre2.h /opt/homebrew/opt/php@7.4/include/php/ext/pcre/pcre2.h
1

启用 swoole

cat >/opt/homebrew/etc/php/7.4/php.ini <<EOF
extension=swoole.so
swoole.use_shortname='Off'
EOF
1
2
3
4

验证验证是否成功

php -m | grep swoole
1

# 安装 redis 扩展

pecl install redis
1

# YASD

# 安装依赖

最高 1.76

brew install boost@1.76 
1

如果找不到 boost 依赖

sudo ln -s /opt/homebrew/Cellar/boost@1.76/1.76.0_4/include/boost /usr/local/include/boost
sudo ln -sf /opt/homebrew/Cellar/boost@1.76/1.76.0_4/lib/libboost_filesystem.dylib /usr/local/lib
1
2

# 编译安装

git clone https://github.com/swoole/yasd.git
1
phpize --clean && \
	phpize && \
	./configure && \
	make clean && \
	make && \
	make install
1
2
3
4
5
6

# 配置

cat >> /opt/homebrew/etc/php/7.4/php.ini <<EOF
zend_extension=yasd
yasd.debug_mode=remote
yasd.remote_host=127.0.0.1
yasd.remote_port=9000
EOF  
1
2
3
4
5
6
Last Updated: 8/18/2023, 7:01:28 AM