Linux 安装Swoole
练习环境:
虚拟机:Oracle VM VirtualBox 5.2.4 r119785 (Qt5.6.2)。 (推荐学习:swoole视频教程)
系统:CentOS Linux release 7.6.1810 (Core) x86_64-Minimal版。
(1)建立一个目录放swoole的安装文件cd /data
mkdir rpm
(2)打开swoole的github地址:https://github.com/swoole/swoole-src/releases
(3)找到需要的版本,例如4.3.4,下载:wget -c https://github.com/swoole/swoole-src/archive/v4.3.4.tar.gz
(4)解压:tar -xzvf v4.3.4.tar.gz
(5)检查一下环境和依赖要求,查看swoole官网:https://wiki.swoole.com/。
查看依赖,https://wiki.swoole.com/wiki/page/7.html。
查看编译安装的准备:https://wiki.swoole.com/wiki/page/6.html。
安装前必须保证系统已经安装了下列软件php-7.0 或更高版本
gcc-4.8 或更高版本
make
autoconf
pcre (CentOS系统可以执行命令:yum install pcre-devel)
检查命令:php -v 查看php版本
gcc -v 查看gcc版本
rpm -qa make 检查是否安装make。
rpm -qa autoconf 检查是否安装autoconf。
rpm -qa pcre 检查是否安装pcre。
(6)配置编译:phpize && \
./configure\
--enable-coroutine \
--enable-openssl \
--enable-http2 \
--enable-async-redis \
--enable-sockets \
--enable-mysqlnd && \
make clean && make
如果报错:configure: error: Cannot find php-config. Please use --with-php-config=PATH
找到php的目录,找到php-config的位置,例如:phpize && \
./configure --with-php-config=/usr/local/php/bin/php-config \
--enable-coroutine \
--enable-openssl \
--enable-http2 \
--enable-async-redis \
--enable-sockets \
--enable-mysqlnd && \
make clean && make
(7)安装:make install
(8)php添加swoole扩展
使用php --ini查看php.ini的位置,执行结果示例:Configuration File (php.ini) Path: /usr/local/php/etc
Loaded Configuration File: /usr/local/php/etc/php.ini
Scan for additional .ini files in: /usr/local/php/conf.d
Additional .ini files parsed: (none)
编辑php.inivim /usr/local/php/etc/php.ini
添加:extension=swoole.so
保存退出。
(9)验证是否安装成功php --ri swoole
查看版本:php --ri swoole | grep Version
可以看到已安装成功。