pecl安装swoole扩展怎么开启openssl

这是一篇基础知识补习文章,大多数新手在安装Swoole扩展时,都只会使用pecl进行安装,还要增加一些编译参数,比如openssl

使用命令进行安装:

pecl install swoole

在使用pecl进行安装时有几个问答选项

enable sockets supports? [no] : 
enable openssl support? [no] : 
enable http2 support? [no] : 
enable mysqlnd support? [no] : 

这些是用于开启某些特性,比如openssl是来启用SSL支持,大多数新手在这里都会选择yes,之后就开始编译了

结果发现报错了:error "Enable openssl support, require openssl library."(具体的错误信息就不详细写了,大概是这样)意思就是说你开启openssl,常规路径下没有找到,需要你手动指定openssl库的路径

或者fatal error: 'openssl/ssl.h' file not found

这个意思是你没有加openssl库的路径或者指定openssl库的路径不对,缺少头文件

那么在pecl安装的时候怎么开启添加这个路径呢?不是只能yes或者no吗?

答案是当然可以添加的,我们可以在yes后面跟上路径参数: --with-openssl-dir=/opt/openssl/,替换为你的openssl库路径

就是这样的:

enable sockets supports? [no] : yes
enable openssl support? [no] : yes --with-openssl-dir=/usr/include/openssl/
enable http2 support? [no] : no
enable mysqlnd support? [no] : yes

下面我们就可以看到我们的编译参数:

building in /tmp/pear/temp/pear-build-rootVseYYu/swoole-4.4.8
running: /tmp/pear/temp/swoole/configure --with-php-config=/usr/local/php/bin/php-config --enable-sockets=yes --enable-openssl=yes --with-openssl-dir=/usr/include/openssl --enable-http2=no --enable-mysqlnd=yes

这样编译完成后就可以了

# php --ri swoole

swoole

Swoole => enabled
Author => Swoole Team 
Version => 4.4.8
Built => Oct 17 2019 11:18:01
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.0.2k-fips  26 Jan 2017
http2 => enabled
pcre => enabled
zlib => enabled
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => 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

2 条评论

发表评论

*