Centos7,PHP7安装swoole
Swoole详细介绍及如何使用,这里暂时不做说明,可以参考一下文档:https://wiki.swoole.com/
源码编译安装
下载地址如下:
- https://github.com/swoole/swoole-src/releases
- http://pecl.php.net/package/swoole
- http://git.oschina.net/swoole/swoole
载源代码包后,在终端进入源码目录,执行下面的命令进行编译和安装
cd swoole phpize ./configure make sudo make install
PECL方式安装
如果pecl还没有安装,可以按照如下方式安装
//php版本 > 7 $ wget http://pear.php.net/go-pear.phar $ php go-pear.phar //php版本 < 7 $ yum install php-pear //否则会报错PHP Parse error: syntax error, unexpected //'new' (T_NEW) in /usr/share/pear/PEAR/Frontend.php on //line 91
下面开始安装swoole
pecl install swoole
//报错如下 //Warning: Invalid argument supplied for foreach() in //Command.php on line 249
需要修改如下配置:
vi `which pecl`
// 找到最后一行 exec $PHP -C -n -q $INCARG -d date.timezone=UTC -d output_buffering=1 -d variables_order=EGPCS -d safe_mode=0 -d register_argc_argv="On" $INCDIR/peclcmd.php "$@" // 去掉 -n 标示,保存退出
修改完成后,再次安装
pecl install swoole // 报错如下 running: phpize Can't find PHP headers in /usr/include/php The php-devel package is required for use of this command. ERROR: `phpize' failed // 需要安装 php-devel扩展
下面安装php-devel扩展
yum install php-devel // 报错如下 Error: php71w-common conflicts with php-common-5.4.16-43.el7_4.1.x86_64 You could try using --skip-broken to work around the problem You could try running: rpm -Va --nofiles --nodigest
以上报错原因是,linux系统的默认php版本是5.4,当前php版本为7.1.14,所以在安装扩展的时候,要指定PHP 版本来安装扩展,操作如下:
// php71w-* 方式安装扩展 yum install php71w-devel
以上安装成功后就可以继续安装swoole了
// 出现如下提示信息,swoole就安装成功啦 Build process completed successfully Installing '/usr/lib64/php/modules/swoole.so' install ok: channel://pecl.php.net/swoole-2.1.3 configuration option "php_ini" is not set to php.ini location You should add "extension=swoole.so" to php.ini
最后需要配置php.ini文件,将extension=swoole.so添加进去
// 查找php.ini文件地址 php -i | grep php.ini Configuration File (php.ini) Path => /etc Loaded Configuration File => /etc/php.ini
修改完成后,重启Apache
systemctl restart httpd
如下图,即表示swoole扩展安装成功