一条大河

用 phpize 编译安装 phpredis 扩展(PECL 扩展库)

有时候不能用 pecl 命令安装想要的扩展,此时可以使用官方提供的 phpize 扩展库编译环境,此文就是演示用 phpize 安装 redis 扩展。

$ cd extname
$ phpize
$ ./configure
$ make
# make install

编译安装按顺序使用的命令如上所示,现在开始(我的系统 MacOS)

一、从 github 拉取 phpredis 扩展源代码

git clone https://github.com/phpredis/phpredis
git checkout -b release/5.3.5 # 切换到发布版本分支(可选)
cd phpredis

二、通过 phpize 适配 phpredis 扩展

注:可用 phpize --help 取得执行命令的绝对路径

sudo /usr/local/opt/php@7.2/bin/phpize

成功输出内容,大概如下:

... ...

Configuring for:
PHP Api Version:         20170718
Zend Module Api No:      20170718
Zend Extension Api No:   320170718

三、编译前指定 php 配置获取路径(官方 php-config 解释)

./configure --with-php-config=/usr/local/Cellar/php@7.2/7.2.29/bin/php-config

成功输出内容,大概如下:

... ...

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h

四、配置准备就绪,开始编译安装

make && make install

成功输出内容,大概如下:

... ...

----------------------------------------------------------------------
Libraries have been installed in:
/Users/andy/code/project/free-andy/phpredis/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `DYLD_LIBRARY_PATH' environment variable
during execution

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

Installing shared extensions: /usr/local/Cellar/php@7.2/7.2.29/pecl/20170718/

五、修改 php.ini 文件配置

注:php --ini 可以找到配置文件路径

vim /usr/local/etc/php/7.2/php.ini

在 Dynamic Extensions 配置组下,添加一行 extension=redis.so

最后重启 php 和 php-fpm ,使用 php -m 看到 redis 就说明安装成功了。

(完)

  • 评论列表
  • 不凡   于 2022-01-10 17:14:40  
  • 你这是在自己的mac电脑安装网站运行环境吗?
    • 大河   于 2022-01-10 17:20:12  
    • PHP 扩展

发表评论

◎发表您的看法、交流您的观点,保持友善言论。

搜索
近期留言
近期发表
站点标签
©
 iddahe.com / PHP函数速查 / 服务器资源 / 代理IP资源 / 海内外高防CDN / 咨询及反馈 / 需求定制 / 使用协议
一条大河(一会儿是风,一会儿是水) Z-BlogPHP 驱动 / Theme: Hipaper / RSS / Sitemap