美文网首页
Centos php swoole 扩展安装

Centos php swoole 扩展安装

作者: 师娘哪里去了 | 来源:发表于2020-03-21 08:02 被阅读0次

安装SWOOLE 扩展

官方下载源码:https://github.com/swoole/swoole-src/releases

cd /opt/
wget https://github.com/swoole/swoole-src/archive/v4.4.16.tar.gz
tar zxvf v4.4.16.tar.gz
cd swoole-src-4.4.16

进入源码目录后,执行PHP扩展命令: phpize

#如果不知道phpize在哪里,可以使用 find / -name phpize 找出其位置
/usr/local/php-7.3.16/bin/phpize
Configuring for:
PHP Api Version:         20170718
Zend Module Api No:      20170718
Zend Extension Api No:   320170718

产生configure文件后,执行编译程序

 ./configure --with-php-config=/usr/local/php-7.3.16/bin/php-config
...
make
make install

编译错误解决

如果产生下方错误:
cc1plus: error: unrecognized command line option "-std=c++11"
则是因为g++ gcc的版本太低所至,更新至高版本即可

安装仓库

#安装仓库
wget http://people.centos.org/tru/devtools-2/devtools-2.repo
mv devtools-2.repo /etc/yum.repos.d
 
#升级gcc等
yum install devtoolset-2-gcc devtoolset-2-binutils devtoolset-2-gcc-c++

新版本的gcc安装在/opt/rh/devtoolset-2/root/ 下。

配置

#保持一个良好的习惯很重要,先备份以前的gcc
mv /usr/bin/gcc /usr/bin/gcc-4.4.7
mv /usr/bin/g++ /usr/bin/g++-4.4.7
mv /usr/bin/c++ /usr/bin/c++-4.4.7
 
#为新版本的gcc创建软连接
ln -s /opt/rh/devtoolset-2/root/usr/bin/gcc /usr/bin/gcc
ln -s /opt/rh/devtoolset-2/root/usr/bin/c++ /usr/bin/c++
ln -s /opt/rh/devtoolset-2/root/usr/bin/g++ /usr/bin/g++

## 检查一下
gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-2/root/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/opt/rh/devtoolset-2/root/usr --mandir=/opt/rh/devtoolset-2/root/usr/share/man --infodir=/opt/rh/devtoolset-2/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --enable-languages=c,c++,fortran,lto --enable-plugin --with-linker-hash-style=gnu --enable-initfini-array --disable-libgcj --with-isl=/dev/shm/home/centos/rpm/BUILD/gcc-4.8.2-20140120/obj-x86_64-redhat-linux/isl-install --with-cloog=/dev/shm/home/centos/rpm/BUILD/gcc-4.8.2-20140120/obj-x86_64-redhat-linux/cloog-install --with-mpc=/dev/shm/home/centos/rpm/BUILD/gcc-4.8.2-20140120/obj-x86_64-redhat-linux/mpc-install --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.2 20140120 (Red Hat 4.8.2-15) (GCC) 

重新编译

然后清除编译缓存,再次执行编译:

make clean
 ./configure --with-php-config=/usr/local/php-7.3.16/bin/php-config
make
...
make install
make install
Installing shared extensions:     /usr/local/php-7.3.16/lib/php/extensions/no-debug-non-zts-20170718/
Installing header files:          /usr/local/php-7.3.16/include/php/

找到php.ini文件,最后一行加入:
extension=swoole.so

重启php-fpm

killall php-fpm
php-fpm

#查看是否已经安装成功
php -m | grep swoole
swoole

至此安装成功!

相关文章

网友评论

      本文标题:Centos php swoole 扩展安装

      本文链接:https://www.haomeiwen.com/subject/ovieyhtx.html