WordPress优化–宝塔Linux面板编译PHPRedis安装支持Zstandard压缩

2024年12月31日教程大全igbinary,PHPRedis,redis,Redis Object Cache Pro,wordpress,WordPress优化,Zstandard,zstd,宝塔面板

教程总目录:WordPress速度优化菜鸟实用版

本文是 使用 Redis Object Cache Pro 高性能模式 文章的配套内容。主要目的是重新编译安装PHP的Redis扩展支持Zstandard压缩,来开启 Redis Object Cache Pro 高性能模式。

默认在宝塔PHP扩展里安装了igbinary和zstd后,我们如果使用宝塔继续安装PHP Redis扩展,他不会支持Zstandard压缩。Redis Object Cache Pro会报以下错误

An error occurred during the instantiation of the configuration:

PhpRedis was not compiled with Zstandard compression support, see For more information about enabling compressions see: https://objectcache.pro/docs/data-encoding/

下面说下如何操作解决这个错误。

安装igbinary和zstd扩展

这两个扩展我们在宝塔面板上安装就可以了,安装后不需要其他操作。

卸载默认安装的PHP Redis

如果您之前安装了宝塔面板PHP扩展中的Redis,那么在这里你需要卸载掉它。卸载后我们使用编译的方式重新安装。

请注意:宝塔面板卸载PHP Redis扩展可能会将Redis程序一起卸载掉。

本文发布时,使用的测试服务器Debian12系统,宝塔免费版9.0.0会连Redis同时卸载掉。被卸载了就重新装下就好了。

编译安装PHP Redis

连接服务器SSH,输入下面的命令执行操作就可以,中间无需其他操作。

下面命令中使用的是宝塔PHP74版本,如果您使用的其他PHP版本,请将74换成您使用的版本号。

apt install libzstd-dev -y
cd ~
wget https://pecl.php.net/get/redis -O redis.tgz
tar -zxvf redis.tgz
cd ~/redis-*
/www/server/php/74/bin/phpize
./configure --with-php-config=/www/server/php/74/bin/php-config --enable-redis-igbinary --enable-redis-zstd
make && make install
echo -e "\n[redis]\nextension = /www/server/php/74/lib/php/extensions/no-debug-non-zts-20190902/redis.so\n" >> /www/server/php/74/etc/php.ini
echo -e "\n[redis]\nextension = /www/server/php/74/lib/php/extensions/no-debug-non-zts-20190902/redis.so\n" >> /www/server/php/74/etc/php-cli.ini
/etc/init.d/php-fpm-74 reload
cd ~ && rm -rf ~/redis-* ~/redis.tgz

完成后我们查看PHP配置文件内容如下图:

安装完成后我们查看Redis Object Cache Pro就可以开启缓存了。

 

 

 

参考信息:

https://objectcache.pro/docs/data-encoding/

https://github.com/igbinary/igbinary

https://github.com/phpredis/phpredis/blob/develop/INSTALL.md

Posted by 柴郡猫