[转]阿里云 Linux 安装phpredis扩展 How to install Redis and Redis php client
2016-01-19 16:20
821 查看
按照前一篇的安装redis教程的步骤在阿里云装redis扩展的时候各种错误频出,于是乎去翻墙Google了一篇
转自 请翻墙点击打开链接
http://anton.logvinenko.name/en/blog/how-to-install-redis-and-redis-php-client.html
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.
So, how to install Redis from source code? Go to Redis Download page and find there the latest version. Download it and unpack:
[/code]
Next step is to compile with make utility and install:
[/code]
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:
[/code]
Create config:
[/code]
Edit it:
[/code]
Example of minimal configuration:
[/code]
By default redis-server will install in /usr/local/bin/redis-server. Check it whith whereis command:
[/code]
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"
[/code]
Start server
[/code]
And try to connect
[/code]
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:
[/code]
In CentOS:
[/code]
Next step is to download, compile and install phpredis
[/code]
Now it is necessary to add the module to php config for Ubuntu with PHP 5.3
[/code]
for Ubuntu with PHP 5.5
[/code]
for CentOS
[/code]
You can check PhpRedis with command bellow, after that you should see "OK" inscription
[/code]
Before using PhpRedis in your php scripts don't forget to restart your web server
if this is Apache
[/code]
if nginx
[/code]
Methods for Redis class available on page PhpRedis
Redis official documentation
try Redis online
The Little Redis Book is a free book about Redis, available in English, Russian and Italian
Databasesredis cache php highload
转自 请翻墙点击打开链接
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-*
[/code]
Next step is to compile with make utility and install:
make sudo make install clean
[/code]
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
[/code]
Create config:
mkdir /etc/redis cp redis.conf /etc/redis/redis.conf
[/code]
Edit it:
nano /etc/redis/redis.conf
[/code]
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
[/code]
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
[/code]
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
[/code]
Start server
redis-server /etc/redis/redis.conf
[/code]
And try to connect
redis-cli
[/code]
PhpRedis Installation
PhpRedis - PHP extension from Nicolas Favre-Felix, which allows to access to Redis from php. Why PhpRedis? There are otherphp 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
[/code]
In CentOS:
yum install php5-dev
[/code]
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
[/code]
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
[/code]
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
[/code]
for CentOS
touch /etc/php.d/redis.ini echo extension=redis.so > /etc/php.d/redis.ini
[/code]
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\"; }"
[/code]
Before using PhpRedis in your php scripts don't forget to restart your web server
if this is Apache
/etc/init.d/apache2 restart
[/code]
if nginx
/etc/init.d/nginx restart
[/code]
Methods for Redis class available on page PhpRedis
Useful resources:
Redis official documentationtry Redis online
The Little Redis Book is a free book about Redis, available in English, Russian and Italian
Databasesredis cache php highload
相关文章推荐
- 一个关于if else容易迷惑的问题
- Linux socket 初步
- Linux Kernel 4.0 RC5 发布!
- linux lsof详解
- linux 文件权限
- Linux 执行数学运算
- 10 篇对初学者和专家都有用的 Linux 命令教程
- PHP5.2.*防止Hash冲突拒绝服务攻击的Patch
- 深入理解PHP之匿名函数
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- Ubuntu Linux使用体验
- JSP/PHP基于Ajax的分页功能实现