>

linux下Swoole编译安装

Linux / 64人浏览 / 0人评论

此教程系统相关配置信息

linux+CentOS

[root@iZm5e86n6s2oqyjbprukreZ swoole-src-4.5.2]# lsb_release -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch
Distributor ID:	CentOS
Description:	CentOS Linux release 8.0.1905 (Core) 
Release:	8.0.1905
Codename:	Core


PHP版本

[root@iZm5e86n6s2oqyjbprukreZ swoole-src-4.5.2]# php -v
PHP 7.2.24 (cli) (built: May 11 2020 12:09:51) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

php的安装路径: /usr/local/php

php.ini配置文件:/usr/local/php/etc/php.ini

phpize文件位置:/usr/local/php/bin/phpize

使用本教程之前,先确认文件路径是否一致(不一样的不要傻瓜式的套用,要学会比葫芦画瓢)


1.为了方便管理扩展文件,我把需要下载的源码包放在了/usr/local/src目录下(可根据自身需求)

cd /usr/local/src


2.下载swoole源码

wget  https://github.com/swoole/swoole-src/archive/v4.5.2.tar.gz


3.解压源码包

tar zxvf v4.5.2.tar.gz


4.进入解压目录
cd swoole-src-4.5.2

5.运行phpize
/usr/local/php/bin/phpize


6.配置信息
./configure --with-php-config=/usr/local/php/bin/php-config


7.安装
make && make install


8.修改php.ini文件

vi /usr/local/php/etc/php.ini

按shift+i 进入编辑模式

查找extension_dir = "ext",修改值为/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718(此值并不是一成不变的)

然后添加一行extension = swoole.so

按esc退出编辑模式,按ctrl+: ,再按wq!保存退出


9.重启php-fpm

service php-fpm restart


10.重启时可能出现的报错(没报错直接跳过)

Gracefully shutting down php-fpm . done
Starting php-fpm [22-Jun-2020 11:47:09] NOTICE: PHP message: PHP Warning:  PHP Startup: Unable to load dynamic library 'swoole.so' (tried: /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/swoole.so (/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/swoole.so: cannot open shared object file: No such file or directory), /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/swoole.so.so (/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/swoole.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library 'swoole.so' (tried: /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/swoole.so (/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/swoole.so: cannot open shared object file: No such file or directory), /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/swoole.so.so (/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/swoole.so.so: cannot open shared object file: No such file or directory)) in <b>Unknown</b> on line
这个是因为/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718下没有swoole.os导致


重新编译一下,依次执行

cd /usr/local/src/swoole-src-4.5.2
phpize && ./configure --with-php-config=/usr/local/php/bin/php-config && make && sudo make install

运行结果最后两行如下

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/
Installing header files:          /usr/local/php/include/php/

11.再次重启php-fpm,查看是否安装成功

php -m

结果如下

[PHP Modules]
bcmath
Core
ctype
curl
date
dom
filter
ftp
gd
gettext
hash
iconv
intl
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
swoole
sysvsem
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
xsl
zip
zlib

[Zend Modules]


运行phpinfo()也可查看,结果如下



如果能看到swoole,就说明安装成功了



版权声明: 本博客所有文章除特别声明外,均属原创。转载请注明来源!


0 条评论

还没有人发表评论

发表评论 取消回复

记住我的信息,方便下次评论
有人回复时邮件通知我