首页PHP文章详情

完美解决 pecl install swoole扩展安装提示openssl无法安装的错误

By lakeui / Sep 9, 2021 阅读 0 评论 0 发表于 PHP 字数:2060 阅读时间:21秒

swooleopenssl

摘要:很多人在安装Swoole扩展时,大部分采用 pecl 进行安装,可有时会遇到,openssl扩展安装失败的提示:error "Enable openssl support, require openssl library." 或者 fatal error: 'openssl/ssl.h' file not found

安装swoole扩展命令:

  1. pecl install swoole

接下来会有以下安装提示:

  1. enable openssl support? [no] :

openssl是用于开启SSL 支持,很多要么输入yes要么输入no,可以输入yes 之后就开始编译了,结果发现报错了:

  1. error "Enable openssl support, require openssl library."

意思就是说你开启 openssl,常规路径下没有找到,需要你手动指定 openssl 库的路径。

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

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

那么在 pecl 安装的时候怎么开启添加这个路径呢?

我们可以在 yes 后面跟上路径参数:

  1. #这里要替换你本地openss的路径
  2. --with-openssl-dir=/usr/local/opt/openssl@1.1

mac系统可以通过下面命令查看:

  1. brew info openssl
  2. For compilers to find openssl@1.1 you may need to set:
  3. export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  4. export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

最后的效果如下:

  1. enable openssl support? [no] : yes --with-openssl-dir=/usr/local/opt/openssl@1.1

这样就可以编译成功,最后查看下:

  1. php --ri swoole
  2. Swoole => enabled
  3. Author => Swoole Team <team@swoole.com>
  4. Version => 4.7.1
  5. Built => Sep 11 2021 16:58:27
  6. coroutine => enabled with boost asm context
  7. kqueue => enabled
  8. rwlock => enabled
  9. sockets => enabled
  10. openssl => OpenSSL 1.1.1l 24 Aug 2021
  11. dtls => enabled
  12. http2 => enabled
  13. pcre => enabled
  14. zlib => 1.2.11
  15. brotli => E16777225/D16777225
  16. async_redis => enabled

可以查看到openssl已经安装成功了!

扩展知识

swoole 编译参数

通用参数

—enable-openssl

启用 SSL 支持

使用操作系统提供的 libssl.so 动态连接库

—with-openssl-dir

启用 SSL 支持并指定 openssl 库的路径,需跟上路径参数,如: —with-openssl-dir=/opt/openssl/

—enable-http2

开启对 HTTP2 的支持

依赖 nghttp2 库。在 v4.3.0 版本后不再需要安装依赖,改为内置,但仍需要增加该编译参数来开启 http2 支持

—enable-swoole-json

启用对 swoole_substr_json_decode 的支持

依赖 json 扩展,v4.5.7 版本可用

—enable-swoole-curl

启用对 SWOOLE_HOOK_NATIVE_CURL 的支持

v4.6.0 版本可用。如果编译报错 curl/curl.h: No such file or directory,请查看安装问题

—enable-cares

启用对 c-ares 的支持, 一个C语言的异步DNS解析库

依赖 c-ares 库,v4.7.0 版本可用。如果编译报错 ares.h: No such file or directory,请查看安装问题

特殊参数

如无历史原因不建议启用

—enable-mysqlnd

启用 mysqlnd 支持,启用 Coroutine\MySQL::escapse 方法。启用此参数后,PHP 必须有 mysqlnd 模块,否则会导致 Swoole 无法运行。

依赖 mysqlnd 扩展

—enable-sockets

增加对 PHP 的 sockets 资源的支持。开启此参数,Swoole\Event::add 就可以添加 sockets 扩展创建的连接到 Swoole 的事件循环中。
Server 和 Client 的 getSocket() 方法也需要依赖此编译参数。

依赖 sockets 扩展,v4.3.2 版本后该参数的作用被削弱了,因为 Swoole 内置的 Coroutine\Socket 可以完成大部分事情

Debug 参数

生产环境不可以启用

—enable-debug

打开调试模式。使用 gdb 跟踪需要在编译 Swoole 时增加此参数。

—enable-debug-log

打开内核 DEBUG 日志。(Swoole 版本 >= 4.2.0)

—enable-trace-log

打开追踪日志,开启此选项后 swoole 将打印各类细节的调试日志,仅内核开发时使用

PHP 编译参数

—enable-swoole

静态编译 Swoole 扩展到 PHP 中

此选项是在编译 PHP 而不是 Swoole 时使用的

手机扫码阅读,舒服~

⌘ + Return 发表
最新 最早 全部评论0 条评论