Installing Redis and PHP Redis extensions under Linux
Environment configuration: centos6.0 nginx/1.0.0 php/5.3.8 mysql/5.5.17
Step one, download Redis
can go to http://redis.io/to download the latest version
I'm using a Redis 2.8.11.
Go to the Software installation package storage directory: cd/var/install/software/
wget http://download.redis.io/redis-stable.tar.gz
Step two, compile the source program
Tar xvzf redis-stable.tar.gz
CD redis-stable
Make
Make install
If make has an exception:
1) make[2]: Cc:command not found
Exception reason: GCC is not installed
Solution: Yum Install gcc-c++
2) zmalloc.h:51:31:error:jemalloc/jemalloc.h:no such file or directory
Exception reason: Some compiler dependencies or original compilation legacy problems
Solution: Make Distclean. Clean it up and make it again.
After make is successful, make test is required to have an exception in make test
1) couldn ' t execute "tclsh8.5": No such file or directory
Exception reason: Tcl not installed
Solution: Yum install-y tcl.
When the make command is completed, 5 executables are generated in the SRC directory, namely Redis-server, REDIS-CLI, Redis-benchmark, redis-check-aof, Redis-check-dump, Their role is as follows:
Redis-server:redis Server Daemon Startup program
Redis-cli:redis command-line operation tool. Of course, you can also use Telnet to operate on its plain text protocol.
Redis-benchmark:redis Performance testing tools to test the read and write performance of Redis in your system and in your configuration
Redis-check-aof: Update log check
Redis-check-dump: for local database checking
Step three, configure
CP redis-server/usr/local/bin/
CP redis-cli/usr/local/bin/
Then create a new directory, store the configuration file
Mkdir/etc/redis
Mkdir/var/redis
Mkdir/var/redis/log
Mkdir/var/redis/run
mkdir/var/redis/6379
Locate the profile template in the Redis solution directory and copy it to the following location.
CP redis.conf/etc/redis/6379.conf modified with vim command
Daemonize Yes
Pidfile/var/redis/run/redis_6379.pid
Logfile/var/redis/log/redis_6379.log
dir/var/redis/6379
Finally, run Redis:
$ redis-server/etc/redis/6379.conf
Available NETSTAT–ATLN View port is a successful boot installation
Step four, Operation Redis database
#./redis-cli
"http://img.blog.csdn.net/20140617150954812?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaV9icnVjZQ==/font/ 5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/southeast "alt=" "/>
Let's take a brief look at the database. In case the instance is turned on:
1. Inserting data
Redis 127.0.0.1:6379> Set name WWL
Ok
Set a Key-value pair.
2. Query data
Redis 127.0.0.1:6379> Get Name
"WWL"
Remove the value corresponding to the key.
3. Delete key values
Redis 127.0.0.1:6379> del name
Delete this key and the corresponding value.
4. Verify that the key is present
Redis 127.0.0.1:6379> exists name
(integer) 0
0, which means that the key does not exist; 1 stands for existence.
Step five, download the Phpredis extension
Download Https://github.com/nicolasff/phpredis/downloads first.
#wget https://github.com/nicolasff/phpredis/downloads
# TAR-ZXVF Nicolasff-phpredis-2.1.3-124-gd4ad907.tar.gz
# MV nicolasff-phpredis-d4ad907 php-5.3.8/ext/phpredis/
# CD php-5.3.8/ext/phpredis/
#/usr/local/php/bin/phpize
#./configure--with-php-config=/usr/local/php/bin/php-config
# Make && make install
Configure PHP.ini
Vi/usr/local/php/lib/php.ini
Join
Extension=redis.so
)
First to see if there is extension_dir=/....
Restart Apache or nginx (reload PHP--->/etc/init.d/php-fpm restart)
To the normal situation, you can see the Redis extension with Phpinfo
If Phpinfo does not have Redis extension information, add/etc/php.d/redis.ini (path is my local)
Redis.ini content is as follows:
; Enable MySQL Extension module
Extension=redis.so
Restart Apache or nginx (reload PHP--->/etc/init.d/php-fpm restart)