ubuntu安装swoole

自动安装最新swoole

1: pecl傻瓜一键式安装swoole:https://www.swoole.co.uk/docs/get-started/installation

//For Debian-based Linux distros you need a php-dev and pkg-php-tools packages 
//to build native PHP extension from phpredis source code
sudo apt update
sudo apt install php-dev pkg-php-tools --yes
sudo pecl channel-update pecl.php.net
sudo pecl install swoole

 安装新的pecl的程序文件夹都放在最新的20200930下面(php8)

2:enable swoole.so在php.ini里

//找到扩展路径, Loaded Configuration File 一项显示的是加载的 php.ini 文件位置
php --ini

//修改配置文件
sudo vim /etc/php/8.0/cli/php.ini

//在50%的位置增加一条记录
extension=swoole.so

3:安装后发现报错swoole:

最新版的原因:https://github.com/swoole/swoole-src/issues/3952

按下面步骤解决:

//定位mods-available文件夹的位置
sudo find / -name mods-available

cd /etc/php/8.0/mods-available

//增加一个swoole.ini文件
sudo vim swoole.ini  

//Add below settings, and save the ini file
;configuration for php common module
;priority=20
extension=swoole.so

5: make sure the swoole.ini are added in

6: 加载swoole module:

sudo phpenmod swoole

 7:确认swoole模块启动

php -m

 

8:补充:一般安装新的extension的路径在:

Installing '/usr/lib/php/20200930/xdebug.so'

php的extension ini配置文件在:/etc/php/8.0/mods-available 

手动安装其他老版本的swoole

1: 安装环境依赖:

2:下载swoole-4.4.3

wget http://pecl.php.net/get/swoole-4.4.3.tgz

download to current location: swoole-4.4.3.tgz

3: 解压:

tar xf swoole-4.4.3.tgz

4: go to swoole root directory + run phpize

cd swoole-4.4.3

/usr/bin/phpize

display your version number: 

5: 设置安装参数: full list of config setting (https://wiki.swoole.com/#/environment)

./configure --enable-openssl --enable-sockets --enable-http2 --with-php-config=/usr/bin/php-config

6: make 进行编译,make install 进行安装

make && make install

 注:如果发现安装错误,permission denied, 要给folder权限

cd /usr/lib/php
sudo chown -R shainezhang:shainezhang ./20170718/
cd /swoole-4.4.3
make install

7:添加 Swoole 到 php.ini:

//找到扩展路径, Loaded Configuration File 一项显示的是加载的 php.ini 文件位置
php --ini

vim /etc/php/7.2/cli/php.ini

//找到45%的位置增加一条扩展:
extension=swoole.so

8:验证swoole已经加载

php -m

 

9:查看swoole都启动了那些模块:

php --ri swoole

//结果如下

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.4.3
Built => Mar 13 2021 14:27:30
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.1.1j 16 Feb 2021
http2 => enabled
pcre => enabled
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


 

 

补充:为什么有的命令我安装了但是找不到command,查看全局环境变量是否有可执行文件

//找到php 命令的位置
which php

//一定要在这个bin下面才可以任意位置执行php命令
/usr/bin/php

 

Installing '/usr/lib/php/20200930/xdebug.so'

posted @ 2021-03-13 14:28  若愚Shawn  阅读(1482)  评论(0编辑  收藏  举报