Redis是高效的对象缓存程序。如果您有基于Litespeed (OpenLitespeed)服务器Wordpress网站,且已经安装了LSCache, 那么配合对象缓存程序,能够让您的网站进一步提速。
不过,同为对象缓存程序,Redis和Memcached只能选择一项安装。对于Litespeed/Wordpress系统,这两者作为对象缓存程序在性能上没有太大差异。上一次我们介绍了编译安装Memcached的方法,今天我们将介绍如何安装Redis服务器。
本文作者为香菇肥牛,原文链接为https://qing.su/article/install-redis-for-litespeed.html, 转载需注明原文链接。谢谢!
1. 系统环境
本文的操作系统为Ubuntu 20.04 LTS 64 bit, 服务器操作环境为OpenLitespeed服务器与LSPHP 7.4.
其他版本的安装步骤类似。
2. 安装Redis服务器
我们直接从包管理器安装Redis服务器即可。执行下面的命令:
1 2 | apt-get update && apt-get upgrade -y apt-get install redis -y |
如果您使用的是CentOS系列,安装Redis服务器的命令如下:
1 2 3 | yum update -y yum install epel-release -y yum install redis -y |
3. 编译安装php-redis拓展
Redis的安装要比Memcached简单得多,主要原因是其PHP拓展安装比较方便。
首先,安装必要的编译环境。
1 | apt-get install build-essential zlib1g-dev libexpat1-dev openssl libssl-dev libsasl2-dev libpcre3-dev -y |
然后从pecl获取php-redis源码:
1 2 3 | wget https://pecl.php.net/get/redis -O redis.tgz tar xvf redis.tgz cd redis-* |
开始编译之前,首先需要用phpize将源码预处理。一般情况下,OpenLitespeed不会预装phpize,我们需要额外安装lsphp74-dev包。
1 2 | apt-get install lsphp74-dev -y /usr/local/lsws/lsphp74/bin/phpize7.4 |
现在可以开始编译了。
1 2 3 | ./configure --with-php-config=/usr/local/lsws/lsphp74/bin/php-config7.4 make make install |
make install的时候,系统会提示php-redis拓展的安装路径,如下图。
比如,我这里是/usr/local/lsws/lsphp74/lib/php/20190902/redis.so
因此,编辑php.ini文件,写入redis拓展位置:
1 | echo "extension=/usr/local/lsws/lsphp74/lib/php/20190902/redis.so" >> /usr/local/lsws/lsphp74/etc/php/7.4/litespeed/php.ini |
最后,重启OpenLitespeed:
1 | /usr/local/lsws/bin/lswsctrl restart |
4. 检验php-redis安装
安装好Redis服务器与php-redis拓展后,我们应该能在phpinfo()中看到对应的Redis块,如下图:
在SSH中,我们也可以检测Redis服务器是否正常运行。执行:
1 | redis-cli ping |
如果Redis正常运行,可以看到下面的回应:
1 | PONG |
5. 为WordPress开启Redis对象缓存
安装完毕后,我们只要在LSCache中开启redis功能,即可使用对象缓存了。
如上图。如果正确安装了Redis, 则Redis Extension与Connection Test的值应该均为绿色。
综上,我们在Ubuntu 20.04 LTS操作系统中安装了Redis服务器与lsphp-redis拓展,联用Redis对象缓存与LSCache为WordPress提速。如果您有任何疑问,欢迎在这留言,我将尽量解答。
本文作者为香菇肥牛,原文链接为https://qing.su/article/install-redis-for-litespeed.html, 转载需注明原文链接。谢谢!
测试过效果如何没?
就是正常Redis应该起到的效果,如果需要进一步提升就得自己优化了
Hello. This post was really remarkable, particularly because I was investigating for thoughts on this matter last Friday. Shel Gale Dusen
It was very useful, I can say it was a useful article for me.
Wow, great blog article.Really thank you! Really Great.
If you are going for best contents like I do, only go to see this web page all the time because it presents feature contents, thanks
It is a very good useful article I like to read such articles
You have a quality site, I congratulate you on this
I feel very lucky to follow your page
I love surfing on your pleasant site
You produce quality content, congratulations on this
As a Newbie, I am constantly exploring online for articles that can help me. Thank you Rianon Dore Seow
As the admin of this web page is working, no uncertainty very quickly it will be well-known, due to its quality contents.| Theodosia Herc Sperry
Amazing blog layout here. Was it hard creating a nice looking website like this? Shaun Aurthur Hamer
Here are a few of the web-sites we recommend for our visitors Honor Andros Ringler
I like the efforts you have put in this, thank you for all the great blog posts. Rhonda Chalmers Roer Lola Chris Frazer
Wow, this article is fastidious, my sister is analyzing these kinds of things, thus I am going to tell her. Cyndia Brit Huskey
Wow! So cool! Escher has nothing on you, Lynn. As always, thanks for sharing. Randa Jerri Theodor
I will right away snatch your rss as I can not to find your email subscription hyperlink or e-newsletter service. Do you have any? Kindly permit me understand in order that I could subscribe. Thanks. Nolana Don Gualtiero
I really like and appreciate your post. Thanks Again. Awesome. Martica Demetris Reid
If some one wants expert view concerning running a blog then i recommend him/her to go to see this weblog, Keep up the fastidious job.| Trista Yvor Katharina