This article mainly describes how to install Redis under Linux and expand the Redis in PHP, interested in the friend's reference, I hope to help you.
Part I: Installing Redis
Want to install Redis to this directory
/usr/local/redis
You want to download the installation package to this directory
/usr/local/src
Then the installation process instructions are as follows:
$ Mkdir/usr/local/redis $ cd/usr/local/src $ wget http://redis.googlecode.com/files/redis-2.6.14.tar.gz $ tar xzf redis-2.6.14.tar.gz $ ln-s redis-2.6.14 redis #建立一个链接 $ cd redis $ make Prefix=/usr/local/redi S install #安装到指定目录中
Note the last line above, we specified the installed directory through prefix. If make fails, it is common that GCC is not installed in your system, so you can install it via yum:
Yum Install GCC
After the installation is complete, continue with make.
After you have successfully installed Redis, you will be able to see a bin directory in/usr/local/redis that includes the following files:
Redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server
1. Copy the script to the/ETC/RC.D/INIT.D directory
Part II: Making Redis a service
PS: The script in the/etc/rc.d/init.d/directory is similar to the registry in Windows, and some of the specified scripts will be executed when the system is started
When you install Redis as per the above steps, its service script is located at:
/usr/local/src/redis/utils/redis_init_script
It must be copied to the/ETC/RC.D/INIT.D directory:
Cp/usr/local/src/redis/utils/redis_init_script/etc/rc.d/init.d/redis
If you add a registration service at this point:
Copy the Redis_init_script to/etc/rc.d/init.d/and easily name Redis.
Chkconfig--add Redis
The following error will be reported:
Redis service does not support Chkconfig
2. Change the Redis script
To do this, we need to change the Redis script.
Open the script using VI to view the script information:
Vim/etc/rc.d/init.d/redis
What you see is as follows (the following is a change of good information):
#!/bin/sh #chkconfig: 2345 # simple Redis INIT.D script conceived to work on Linux systems # as it does use of the/ Proc FileSystem. redisport=6379 Exec=/usr/local/redis/bin/redis-server cliexec=/usr/local/redis/bin/redis-cli PIDFILE=/var/run/ Redis_${redisport}.pid conf= "/etc/redis/${redisport}.conf" case "$" in start) if [-F $PIDFILE] t Hen echo "$PIDFILE exists, process is already running or crashed" else echo "Start ing Redis server ... "$EXEC $CONF & fi; STOP) if [!-F $PIDFILE] then echo ' $PIDFILE does not exist, process was not running " Else pid=$ (cat $PIDFILE) echo "Stopping ..." $CLIEXEC-P $REDISPORT s Hutdown while [-x/proc/${pid}] does echo "Waiting for Redis to Shutdo WN ... "Sleep 1 doNe echo "Redis stopped" FI;; *) echo "Please use Start or stop as first argument";; Esac
1. The original document does not have the contents of line 2nd below,
Compared to the original configuration file:
#chkconfig: 2345 90exec=/usr/local/redis/bin/redis-server cliexec=/usr/local/redis/bin/redis-cli
2. The original file exec, cliexec parameters, is also changed.
3.redis commands that are enabled to run in the background.
$EXEC $CONF &
Occupy the front desk, occupying the main user interface, resulting in other commands not being executed.
PS: Note that the "&" in the back, that is, to move the service back to the meaning of running, otherwise when the service is started, the Redis service will
4. Copy the Redis configuration file to/etc/redis/${redisport}.conf
In this way, the conf specified by the Redis service script exists. By default, Redis does not have authentication enabled, and you can specify a verification password by turning on the requirepass of 6379.conf.
Once the above operation is complete, you can register the Yedis service:
Chkconfig--add Redis
Service Redis Start
3. Start the Redis service
Third, add the directory where the Redis command resides to the system parameter path
To modify a profile:
Vi/etc/profile
Append in last line:
Export path= "$PATH:/usr/local/redis/bin"
Then apply this file immediately:
. /etc/profile
This makes it possible to invoke the REDIS-CLI command directly, as follows:
There is insufficient permissions to perform the previous step: chmod 777/etc/profile
$ redis-cli redis 127.0.0.1:6379> auth superman OK redis 127.0.0.1:6379> ping PONG Redis 127.0.0.1:6379>
At this point, Redis is installed successfully.
Download: https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz
Upload phpredis-2.2.4.tar.gz to/usr/local/src directory
CD/USR/LOCAL/SRC #进入软件包存放目录
Tar zxvf phpredis-2.2.4.tar.gz #解压
CD phpredis-2.2.4 #进入安装目录
/usr/local/php/bin/phpize #用phpize生成configure配置文件, the directory may be different. Phpize is an executable file in the bin directory of PHP, all of which need to find the corresponding directory first.
./configure--with-php-config=/usr/local/php/bin/php-config #配置, be careful to ensure that/usr/local/php/bin/php-config exists first. Php-config in the bin directory corresponding to PHP
Make #编译
Make install #安装
After the installation is complete, the following installation path appears
/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
may also appear
Installing Shared extensions:/usr/lib64/php/modules/
This is normal, go on below.
2. Configure PHP Support
Vi/usr/local/php/etc/php.ini #编辑配置文件, add the following on the last line
Add to
extension= "Redis.so"
: wq! #保存退出
Restart httpd------------->ok
Related recommendations:
PHP processing Redis
Redis Application case Study in Nodejs
PHP combined with redis seconds to kill the product of the detailed