-
Install redis and php Redis extension in linux
-
Environment configuration: centos6.0 nginx/1.0.0 php/5.3.8 mysql/5.5.17
-
Step 1. download redis
-
You can download the latest version at http://redis.io/
-
I use 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 2. compile the source program
-
Tar xvzf redis-stable.tar.gz
-
Cd redis-stable
-
Make
-
Make install
-
If an exception occurs in make:
-
1) make [2]: cc: Command not found
-
Cause of exception: gcc is not installed
-
Solution: yum install gcc-c ++
-
2) zmalloc. h: 51: 31: error: jemalloc/jemalloc. h: No such file or directory
-
Cause of exception: Some compilation dependencies or issues left behind by the original compilation
-
Solution: make distclean. Clean up and then make.
-
After make is successful, make test has an exception in make test.
-
1) couldn't execute "tclsh8.5": no such file or directory
-
Cause of exception: tcl is not installed
-
Solution: yum install-y tcl.
-
After the make command is executed, five executable files are generated in the src directory, they are redis-server, redis-cli, redis-benchmark, redis-check-aof, and redis-check-dump. Their functions are as follows:
-
Redis-server: daemon startup program of the Redis server
-
Redis-cli: Redis command line operation tool. Of course, you can also use telnet to operate based on its plain text protocol.
-
Redis-benchmark: Redis performance testing tool to test the read/write performance of Redis in your system and your configuration
-
Redis-check-aof: update log check
-
Redis-check-dump: used for local database check
-
Step 3. configure
-
Cp redis-server/usr/local/bin/
-
Cp redis-cli/usr/local/bin/
-
Create a directory to store the configuration file.
-
Mkdir/etc/redis
-
Mkdir/var/redis
-
Mkdir/var/redis/log
-
Mkdir/var/redis/run
-
Mkdir/var/apsaradb for redis/6379
-
Find the configuration file template in the redis root directory and copy it to the following location.
-
Cp redis. conf/etc/redis/6379. conf is modified using the vim command
-
Daemonize yes
-
Pidfile/var/redis/run/redis_62.16.pid
-
Logfile/var/redis/log/redis_62.16.log
-
Dir/var/redis/6379
-
Finally run redis:
-
$ Redis-server/etc/redis/6379. conf
-
Use netstat-atln to check whether the port is successfully installed.
-
-
Step 4: operate the Redis database
-
#./Redis-cli
-
-
"Http://img.blog.csdn.net/20140617150954812? Watermark/2/text/plain =/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA =/dissolve/70/gravity/SouthEast "alt ="/>
-
Next we will perform a simple operation on the database. When the instance is enabled:
-
1. Insert 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"
-
Obtain the value corresponding to the key.
-
3. delete a key value
-
Redis 127.0.0.1: 6379> del name
-
Delete the key and the corresponding value.
-
4. check whether the verification key exists
-
Redis 127.0.0.1: 6379> exists name
-
(Integer) 0
-
0 indicates that the key does not exist; 1 indicates that the key exists.
-
Step 5. download phpredis extension
-
Download the 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
-
(Add:
-
Extension = redis. so
-
)
-
First, check whether there is extension_dir = /.......
-
Restart apache or nginx (reload php --->/etc/init. d/php-fpm restart)
-
By now, you can use phpinfo to view the redis extension.
-
If phpinfo does not have redis extension information, add/etc/php. d/redis. ini (the path is my local)
-
The content of redis. ini is as follows:
-
; Enable mysql extension module
-
Extension = redis. so
-
Restart apache or nginx (reload php --->/etc/init. d/php-fpm restart)