赶知识网

在mac下安装swoole搭建hyperf开发环境 - 跳坑攻略

2021-03-18 / 1815次点击 OS/操作系统 brew Mac swoole hyperf

第一步,首先需要安装php。最新版本的hyperf依赖要求php7.4-7.5。这样以前安装的php7.2 7.3什么的,都用不上了。。。

require php >=7.4.1,<7.5.0 -> your php version (8.0.3) does not satisfy that requirement

如果执行执行brew install php,系统默认安装的是php8.0。所以正确的选择是:

    brew install php@7.4 

安装完成之后,执行 php -v,看看系统默认的php是不是php7.4。如果不是,参考下面的命令:

    vim ~/.bash_profile
在文件末尾添加一行,加粗的部分,替换成正确的路径:
    export PATH=/usr/local/Cellar/php@7.4/7.4.16/bin:$PATH
    source ~/.bash_profile

第二步,安装swoole的依赖组件。如果直接执行swoole安装命令肯定报错,先安装依赖。swoole的依赖主要有两个:redis和openssl。

    pecl install redis 

    brew install openssl

第三步,可以开始安装swoole了。

    pecl install swoole

这里的坑是安装程序无法自动识别到brew安装的openssl路径。所以在遇到询问是否打开openssl支持的时候,输入下面的命令:

yes --with-openssl-dir=/usr/local/Cellar/openssl@1.1/1.1.1j/

加粗的部分,替换成真实路径。

enable sockets supports? [no] : yes

enable openssl support? [no] : yes --with-openssl-dir=/usr/local/Cellar/openssl@1.1/1.1.1j/

enable http2 support? [no] : yes

enable mysqlnd support? [no] : yes

enable json support? [no] : yes

enable curl support? [no] : yes

第四步,安装hyperf依赖。在hyperf代码目录下执行:composer install 。

如果需要用指定版本的php执行composer:

which is composer

 

/usr/local/Cellar/php/8.0.3/bin/php /usr/local/bin/composer install

 

可能遇到的错误:

error: "Enable openssl support, require openssl library"

 

fatal error: 'openssl/ssl.h' file not found

 

Could not resolve host: d29vzk4ow07wi7.cloudfront.net

 

有用 没用

Top10

沪ICP备09053415号 © 赶知识网