使用EasySwoole之安装Swoole

  •   
  • 2445
  • PHP
  • 0
  • super_dodo
  • 2020/10/16

首先进入swoole的github下载地址:https://github.com/swoole/swoole-src/releases
如果没有特殊需求,请选择最新版本开始下载(我这里是最新版是v4.5.5):

dodo@dev:/dev$ wget https://github.com/swoole/swoole-src/archive/v4.5.5.tar.gz ## 下载

dodo@dev:/dev$ tar -zvxf v4.5.5.tar.gz  ## 解压到当前目录

dodo@dev:/dev$ cd swoole-src-4.5.5/ ## cd目录

dodo@dev:/dev/swoole-src-4.5.5$ phpize ## 使用phpize创建php编译检测脚本 ./configure

dodo@dev:/dev/swoole-src-4.5.5$ ./configure --with-php-config=/usr/local/php-7.2.2/bin/php-config --enable-openssl  ## 创建编译文件,第一个--with,后面是php的安装路径/bin/php-config ,第二个--enable,是开启swoole的ssl功能

dodo@dev:/dev/swoole-src-4.5.5$sudo make && make install  ## 编译swoole并把编译好的文件移动到php的扩展目录(前面的配置php版本的扩展目录) 需要root权限

这个时候已经安装成功,需要进入php.ini,在最后面增加上:
extension=swoole.so

成功安装swoole,通过php --ri swoole 查看swoole扩展的信息:

dodo@dev:/dev/swoole-src-4.5.5$ php --ri swoole


Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.5.5
Built => Oct 16 2020 15:01:50
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
openssl => OpenSSL 1.0.2k-fips  26 Jan 2017
pcre => enabled
zlib => 1.2.7
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608
#到此,swoole安装完毕

常见问题#编译报错

找不到php-config的时候
执行语句 ./configure --with-php-config=/usr/local/php-7.2.2/bin/php-config --enable-openssl
报错信息:configure: error: Cannot find php-config. Please use --with-php-config=PATH

原因:那是因为没有指定PHP的配置文件 所以我们想要知道PHP的文件在哪的时候输入以下命令
原因:因为我之前dev环境是用yum安装的php环境
find / -name php-config
找到php-config所在目录 /usr/bin/php-config

正确的执行语句:
./configure --with-php-config=/usr/bin/php-config --enable-openssl

此外记得多查看phpinfo()的信息.
whereis php
php -v
php -m
php --ini
phpinfo();

常见问题#组件出错

phpize 命令不存在
安装phpize

yum install php-devel ## centos
sudo apt-get install php-dev  ## ubuntu
提示swoole.so.so类似的报错
说明你的phpize版本和php-config设定的版本不一致,请重新编译

phpize命令也可以使用绝对路径:php路径/bin/phpize 用于执行
在之后的--with-php-config也得使用同样的路径:php路径/bin/php-config

安装成功 php --ri没有swoole
说明你的php命令行版本,和安装swoole的php版本不一致,可以通过:php路径/bin/php --ri swoole 进行确认是否安装成功

参考文章:
https://www.easyswoole.com/Cn/QuickStart/installSwoole.html