Redis currently (20150525) has been updated to version 3.0, today we will learn how to deploy Redis on the server and enable PHP support.
Redis logo
I. Redis
Download installation
Each version of Redis can be found in http://download.redis.io/releases/
wget http://download.redis.io/releases/redis-stable.tar.gz
Tar zxf redis-stable.tar.gz
CD redis-stable
Make && make install
# Copy configuration file
CP redis.conf/etc/redis.conf
# Copy binary files to/usr/local/bin
CD src
CP Redis-server REDIS-CLI redis-benchmark/usr/local/bin/
This redis installation is complete.
Configure Redis
After the installation is complete, we need to do some configuration work.
Redis-server-v
#Redis server v=3.0.1 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 BUILD=3858E635DE930C10
# Create a database folder
mkdir/var/lib/redis_db/-P
Vim/etc/redis.conf
# Modify the following variables
Daemonize Yes # daemon Run
LogFile "/var/log/redis.log" # log file
dir/var/lib/redis_db/# Data Persistence folder
Now that the basic operation of Redis has been configured, we will discuss the advanced features such as Master-slave and persistence strategy.
Run Redis
Redis-server/etc/redis.conf
# Check the run log, remember the log file we just configured?
Tail-100/var/log/redis.log
# Show
_._
_.-``__ ''-._
_.-`` `. `_. "'-._ Redis 3.0.1 (00000000/0) bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|' ` _.-'| port:6379
| `-._ `._ / _.-' | pid:19337
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | Http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
19337:m 22:32:40.369 # Server started, Redis version 3.0.1
19337:m 22:32:40.369 # WARNING Overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ' vm.overcommit_memory = 1 ' to/etc/sysctl.conf and then reboot or run the command ' Sysctl vm.overcom Mit_memory=1 ' for this to take effect.
19337:m 22:32:40.369 * DB loaded from disk:0.000 seconds
19337:m 22:32:40.369 * The server is now ready to accept connections on port 6379
Ii. Configuring PHP
Then we compile Phpredis, the project address
Download
git clone https://github.com/phpredis/phpredis.git Phpredis
CD Phpredis
/usr/local/php/bin/phpize
./configure
# The old high environment variable is not imported so the compile command is./configure--with-php-config=/usr/local/php/bin/php-config
Make && make install
If your PHP is not compiled, then phpize needs to perform yum install Php-devel, that is, install the devel version of PHP
When the compilation is complete, you will get
Installing Shared extensions:/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/
We'll copy it out.
cp/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/redis.so/usr/local/php/lib/php/extensions/
Open Redis Extension
Similar to the PHP installation memcached extension, finally we need to add the following configuration in php.ini
Vim/etc/php.ini
# add
[Redis]
Extension=redis.so
After restarting Apache or PHP-FPM, the Phpinfo page