Home  >  Article  >  Backend Development  >  How to install redis extension in php under linux

How to install redis extension in php under linux

藏色散人
藏色散人Original
2021-10-18 10:30:294571browse

How to install the redis extension in php under Linux: 1. Download the phpredis extension; 2. Unzip it through "tar zxvf"; 3. Execute phpize; 4. Specify the php configuration path; 5. Add the extension to the php configuration file php.ini; 6. Restart php.

How to install redis extension in php under linux

The operating environment of this article: linux5.9.8 system, phpredis2.2.4 version, DELL G3 computer

How to install redis in php under linux Extension?

Install Redis on Linux PHP Install Redis extension

1. Download

Download address: wget http://download. redis.io/releases/redis-4.0.8.tar.gz

[root@localhostredis]#wget http://download.redis.io/releases/redis-4.0.8.tar.gz ( If the address is invalid, please change it)

Extract: [root@localhost redis]# tar xzf redis-4.0.8.tar.gz

Rename

[root@localhost redis]# mv redis-4.0.8 redis

Enter Directory cd redis

2. Install redis

Installation: Use the make command

[root@localhost redis]# sudo make && sudo make install

Wait for the installation to complete.

3. Configuration

Run: [root@localhost redis]# src/redis-server You need to execute the command in the redis installation directory.


This does not run redis in the background, so when the command line interface is closed, the link will be lost, so for convenience, we need to configure it as Run in the background

Edit the configuration file: vim redis.conf redis.conf is in the current directory. Change daemonize=no to daemonize=yes and save.

Then start

[root@localhost redis]# src/redis-server ./redis/conf

At this time our The redis service segment is already running in the background.

Then start the client:

src/redis-cli

## Test: set test changyiyi Set key value

Get: get test

The above is the simple installation configuration of redis on Linux. For more syntax about using redis, please refer to the redis official website: https://redis.io/

4.php Install redis extension

Download phpredis extension

Download address: https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz

Execution command:

[root@localhost local] # wget https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz

Unzip: tar zxvf

[root @localhost local]# tar zxvf 2.2.4.tar.gz

Execute phpize

[root@localhost phpredis]# /usr/local/php5 /bin/phpize This is entered according to your actual path

Specify the php configuration path:

[root@localhost phpredis] # ./configure --with-php-config=/usr/local/php5/bin/php-config

Compile and install: sudo make && sudo make install

Execute command: [root@localhost phpredis]# sudo make && make install

Add the extension to the php configuration file php.ini. The path to php.ini is The path of your own environment

[root@localhost phpredis]# vim /etc/php/php.ini

Add a line in it: /usr/local/php5/lib/php/extensions /no-debug-non-zts-20090626/redis.so

Then save and restart php

ps -ef | grep php-fpm

Kill -quit process number

Start php:

/usr/local/php5/sbin/php-fpm

Then check redis in phpinfo() Extension:

#Check whether php has successfully installed the php redis extension and can use it.

Create a test php file redis.php

vim redis.php

Type the content:

66325234f98c2eb2f87f5e1552e3c98f

Execute the php file.

php redis.php

Output: Server is running: PONG.....

Success! You can start using redis happily in php.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to install redis extension in php under linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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