现在项目中运用到缓存越来越多了,笔者也经常用 yum 命令安装,但是今天在 AWS 下安装,yum下没有包。最终采用编译安装,一下将这次安装过程。
一、安装redis
先查找 yum 包:
yum list |grep redis
这边是没有找到包,于是乎开始了下面的编译安装过程。
这个可以从 redis官网 下载,
wget http://download.redis.io/releases/redis-4.0.11.tar.gz
解压并进入目录:
tar xzf redis-4.0.11.tar.gz
cd xzf redis-4.0.11
安装:
make
这边会涉及一个redis 的服务端模式,客户端模式:
#服务端
redis-server
#客户端
redis-cli
我们是需要redis 在后台运行的,所以这边需要配置文件,将redis.conf修改:
daemonize no
改为:
daemonize yes
后台启动redis服务:
redis-server redis.conf
第二、安装插件 (可以参照文档)
在 PHP PECL 查找插件 ,找个稳定的版本,然后下载解压:
wget http://pecl.php.net/get/redis-4.1.1.tgz
tar xzf redis-4.1.1.tgz
这边两个名字很像啊,可以重命名为:
cp redis-4.1.1 redis-php-4.1.1
rm redis-4.1.1
cd redis-php-4.1.1
phpize
$ /usr/bin/phpize 或者 phpize
$ ./configure
$ make
$ make install
/bin/sh /home/ec2-user/redis-4.1.1/libtool --mode=install cp ./redis.la /home/ec2-user/redis-4.1.1/modules
libtool: install: cp ./.libs/redis.so /home/ec2-user/redis-4.1.1/modules/redis.so
libtool: install: cp ./.libs/redis.lai /home/ec2-user/redis-4.1.1/modules/redis.la
libtool: finish: PATH="/sbin:/bin:/usr/sbin:/usr/bin:/sbin" ldconfig -n /home/ec2-user/redis-4.1.1/modules
----------------------------------------------------------------------
Libraries have been installed in:
/home/ec2-user/redis-4.1.1/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 `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Installing shared extensions: /usr/lib64/php/modules/
从上面可以看出,已经生成的redis.so,最后在php.ini添加
extension=redis.so
通过 phpinfo 探针看出,安装成功。
大功告成!