Home > Backend Development > PHP7 > How to install redis extension for php7 in centos7

How to install redis extension for php7 in centos7

醉折花枝作酒筹
Release: 2023-02-17 22:30:02
forward
2277 people have browsed it

This article will introduce to you how to install the redis extension for php7 in centos7. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

How to install redis extension for php7 in centos7

Download redis

Download redis, unzip, compile:

$ wget http://download.redis.io/releases/redis-4.0.6.tar.gz
$ tar xzf redis-4.0.6.tar.gz
$ cd redis-4.0.6
$ make && make PREFIX=/usr/local/redis install  #安装到指定目录
Copy after login

Now go to the tar package and unzip it In the source code directory, copy a redis.conf configuration file and place it in the /usr/local/redis/bin/ directory.

Enter the redis directory and run vi redis.conf

to Change daemonize no to daemonize yes, save and exit

Start the Redis service through the following command:

./bin/redis-server ./redis.conf

You can use the built-in client command redis-cli:

$ ./redis-cli
redis> set foo bar
OK
redis> get foo"bar"
Copy after login

The above is to install the redis program

To enable the redis extension in php7

Use git clone to download the phpredis expansion package on git

[root@localhost local ]#git clone  https://github.com/phpredis/phpredis.git
Copy after login

At this step, we need to use phpize generated when installing php to generate the configure configuration file,

//Specific use Which one depends on the directory where your phpize file is located. In this case, you should use whereis phpize to view the path

[root@localhost local ]# whereis phpize
phpize: /usr/bin/phpize /usr/share/man/man1/phpize.1.gz
Copy after login

This indicates that the path is /usr/bin/phpize, and then execute:

[root@localhost phpredis ]# /usr/bin/phpize
Can't find PHP headers in /usr/include/php
The php-devel package is required for use of this command.
Copy after login

An error is reported here. The reason is that php-devel is not installed. Since I am using php7.0, I execute the following command:

[root@localhost phpredis]#yum -y install php70w-devel
Copy after login

and then execute it again:

[root@localhost phpredis]# /usr/bin/phpize
Configuring for:
PHP Api Version: 20151012
Zend Module Api No: 20151012
Zend Extension Api No: 320151012
Copy after login

After executing the previous step, we There is a configure configuration file. Next, configure

[root@localhost phpredis]#./configure
Copy after login

or execute

[root@localhost phpredis]#./configure --with-php-config=/usr/bin/php-config
Copy after login

. Next is to compile and install

[root@localhost phpredis]#make 
[root@localhost phpredis]# make install
 Installing shared extensions:      /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/
Copy after login

to configure the php configuration file php.ini (specifically put There you can use whereis php.ini to view), my configuration file php.ini is under /etc/

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

Enable redis extension:

extension = redis.so
Copy after login

The path of the redis.so file can be found in When making install, I see

[root@localhost local]# php -m #Query the extension of php


Restart the nginx server and restart php-fpm, make the configuration take effect

After restarting, we open info.php and you can already see the extended information of redis

Recommended learning:php video tutorial

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

Related labels:
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