服务器环境:ubuntu+nginx+php7.0
1.安装nghttp2库:
sudo apt-get install nghttp2
或者
sudo wget https://github.com/nghttp2/nghttp2/releases/download/v1.30.0/nghttp2-1.30.0.tar.bz2
sudo tar -jxvf nghttp2-1.30.0.tar.bz2
cd nghttp2-1.30.0
sudo ./configure
sudo make && make instal
2.下载swoole :
sudo pecl install swoole
在进行编译的时候,根据自己需求选择开启的扩展(PostgreSQL 这个选项我选择的是no)
3.修改php.ini
cd /etc/php/7.0/cli
sudo vi php.ini
加入 extension=swoole.so
保存退出。
附:
确认php.ini的位置
sudo php -i|grep php.ini
如果在执行php -v报错如下
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/swoole.so' - libnghttp2.so.14: cannot open shared object file: No such file or directory in Unknown on line 0
PHP 7.0.30-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.30-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies
解决办法
sudo vi /etc/ld.so.conf
添加
include /usr/local/lib
保存退出
执行命令
sudo ldconfig
重启php-fpm和nginx
sudo service php7.0-fpm restart
sudo service nginx restart
关于php -m或者PHPinfo中没有swoole的信息,参考官方文档
https://wiki.swoole.com/wiki/page/351.html
来源:oschina
链接:https://my.oschina.net/u/3578722/blog/2962943