[转]阿里云 Linux 安装phpredis扩展 How to install Redis and Redis php client

按照前一篇的安装redis教程的步骤在阿里云装redis扩展的时候各种错误频出,于是乎去翻墙Google了一篇

转自 请翻墙点击打开链接

http://anton.logvinenko.name/en/blog/how-to-install-redis-and-redis-php-client.html


How to install Redis and Redis php client

Redis — cache-storage for data that is stored in RAM. In this case you will get very fast data access. It is similar to memcache but Redis has vast opportunities of data storage.

Redis allows you to store not only strings but also lists, sets, sorted sets and hashes. You can find more details about Redis onofficial Redis site. I recommend to install Redis from a source code. In this case you will get the latest version.

Redis installation

So, how to install Redis from source code? Go to Redis Download page and find there the latest version. Download it and unpack:

mkdir /tmp/redis
cd /tmp/redis
wget http://download.redis.io/releases/redis-2.8.8.tar.gz
tar xzf redis-*
cd redis-*

Next step is to compile with make utility and install:

make
sudo make install clean

If you have 64 bit system it is necessary to install libc6-dev-i386 before compile. In Ubuntu it is possible to make with flowing steps:

sudo apt-get install libc6-dev-i386
make 32bit
sudo make install clean

Create config:

mkdir /etc/redis
cp redis.conf /etc/redis/redis.conf

Edit it:

nano /etc/redis/redis.conf 

Example of minimal configuration:

#start as a daemon in background
daemonize yes
#set port, by default is 6379
port 6379
#set ip on which daemon will be listening for connections
bind 127.0.0.1
#where to dump database
dir /var/opt

By default redis-server will install in /usr/local/bin/redis-server. Check it whith whereis command:

whereis redis-server
#redis-server: /usr/local/bin/redis-server

If you want the server be accessible after system start, it is possible to write a line in /etc/rc.local file before "exit 0"

/usr/local/bin/redis-server /etc/redis/redis.conf

Start server

redis-server /etc/redis/redis.conf 

And try to connect

redis-cli

PhpRedis Installation

PhpRedis - PHP extension from Nicolas Favre-Felix, which allows to access to Redis from php. Why PhpRedis? There are other php libraries that allow to communicate with Redis? The answer - speed. This module have been written on C and this mean that this is faster than libraries that have been written on php

We need php5-dev

In Ubuntu it is possible to install with this command:

apt-get install php5-dev

In CentOS:

yum install php5-dev

Next step is to download, compile and install phpredis

sudo -i
cd /tmp
wget https://github.com/nicolasff/phpredis/zipball/master -O phpredis.zip
unzip phpredis.zip
cd phpredis-*
phpize
./configure
make && make install

Now it is necessary to add the module to php config for Ubuntu with PHP 5.3

touch /etc/php5/conf.d/redis.ini
echo extension=redis.so > /etc/php5/conf.d/redis.ini

for Ubuntu with PHP 5.5

touch /etc/php5/conf.d/redis.ini
touch /etc/php5/mods-available/redis.ini
echo extension=redis.so > /etc/php5/mods-available/redis.ini
ln -s /etc/php5/mods-available/redis.ini /etc/php5/apache2/conf.d
ln -s /etc/php5/mods-available/redis.ini /etc/php5/cli/conf.d

for CentOS

touch /etc/php.d/redis.ini
echo extension=redis.so > /etc/php.d/redis.ini

You can check PhpRedis with command bellow, after that you should see "OK" inscription

php -r "if (new Redis() == true){ echo \"\r\n OK \r\n\"; }"

Before using PhpRedis in your php scripts don't forget to restart your web server

if this is Apache

/etc/init.d/apache2 restart

if nginx

/etc/init.d/nginx restart

Methods for Redis class available on page PhpRedis

Useful resources:


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值