Redis is powerful, easy to use, and powerful. It is now a skill that PHPer must master. Leaving aside other application scenarios, using redis to store sessions is something that a PHPer must know.
Redis source code installation
Because most servers are installed with linux operating systems, and redis officially does not support redis in Installed under windows system. Therefore, the following are all installation tutorials for the centOS7 distribution on Linux systems.
First, we need to download the installation package. Download address:
http://download.redis.io/releases/redis-5.0.5.tar.gz
redis does not have any dependencies, so there will be no problems with general installation. If there is any problem, update gcc. The installation process is as follows:
1. Download the installation package
# wget http://download.redis.io/releases/redis-5.0.5.tar.gz
2. Unzip and install
It will take a while during the compilation phase make, please wait patiently
# tar -zxf redis-5.0.5.tar.gz # cd redis-5.0.5 # make # make PREFIX=/usr/local/redis install
3. Create a new redis configuration file directory and data storage directory
# mkdir /usr/local/redis/etc /usr/local/redis/var
4. Copy the configuration file and modify the configuration file
# cp redis.conf /usr/local/redis/etc/ # vim /usr/local/redis/redis.conf
Find the daemonize no line, change no to yes, which means Run in daemon mode and find the dir line. Change it to /usr/local/redis/var to indicate that the data is stored in this directory.
4. Make a soft link
ln -s /usr/local/redis/bin/* /usr/local/bin/
5. Start redis and Testing is normal
# systemctl start redis-server # redis-cli 127.0.0.1:6379> ping PONG
PONG means success
Install phpredis extension
The prerequisite is that the server must have been installed Over php. If it is not installed, install it first. I won’t talk about how to install php here.
The installation package address is here http://pecl.php.net/package/redis. Here I download the latest stable version
# wget http://pecl.php.net/get/redis-5.2.2.tgz
The installation steps are as follows:
1. Unzip
# tar -zxf redis-5.2.2.tgz # cd redis-5.2.2
2. Run phpize
/usr/local/php/bin/phpize
3. Install
# ./configure --with-php-config=/usr/local/php/bin/php-config # make # make install
4. Modify php.ini
Open the php.ini file and add a new line
extension=redis
5. Check whether the extension is installed successfully
# php -m | grep redis
Check if Redis appears.
Close the redis service
Just use the systemctl command normally. One thing to note here is not to use kill -9 to kill. The consequence of this is that not only will redis not be persisted, but it will also easily cause data loss.
The above is the detailed content of Install Redis and php redis extension. For more information, please follow other related articles on the PHP Chinese website!