Home > Database > Redis > body text

Install Redis and php redis extension

齐天大圣
Release: 2020-05-07 10:31:12
Original
3379 people have browsed it

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
Copy after login

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
Copy after login

3. Create a new redis configuration file directory and data storage directory

# mkdir /usr/local/redis/etc /usr/local/redis/var
Copy after login

4. Copy the configuration file and modify the configuration file

# cp redis.conf /usr/local/redis/etc/
# vim /usr/local/redis/redis.conf
Copy after login

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/
Copy after login

5. Start redis and Testing is normal

# systemctl start redis-server
# redis-cli
127.0.0.1:6379> ping
PONG
Copy after login

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
Copy after login

The installation steps are as follows:

1. Unzip

# tar -zxf redis-5.2.2.tgz
# cd redis-5.2.2
Copy after login

2. Run phpize

/usr/local/php/bin/phpize
Copy after login

3. Install

# ./configure --with-php-config=/usr/local/php/bin/php-config 
# make
# make install
Copy after login

4. Modify php.ini

Open the php.ini file and add a new line

extension=redis
Copy after login

5. Check whether the extension is installed successfully

# php -m | grep redis
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template