How to install redis php extension in centos: first download and install redis through "make install"; then start the redis service and modify the "redis.conf" file; then download and install php through relevant commands; finally restart "php -fpm" service.
##CentOS7 Install Redis and PHP-redis extension
daemonize yes
Copy after login
Copy after login
Copy after login
Redis is A key-value storage system, which belongs to what we often call NoSQL. It complies with the BSD protocol, supports the network, can be memory-based and persistent log-type, Key-Value database, and provides APIs in multiple languages. It is commonly used in scenarios such as caching, queues, Pub/Sub, counting statistics, rankings, voting and sorting.
This article introduces how to install redis on CentOS7 and the php-redis extension library that allows PHP to support redis.
Install Redis
Redis official download address: http://redis.io/download, download the latest stable version.
The current stable version is 4.0.9, download and install:
$ wget http://download.redis.io/releases/redis-4.0.9.tar.gz
$ tar -zxvf redis-4.0.9.tar.gz
$ mv redis-4.0.9 /usr/local/redis
$ cd /usr/local/redis
$ make
$ make install
Copy after login
After make is completed, the compiled redis service program redis-server will appear in the redis-4.0.9 directory. There is a client program redis-cli for testing. The two programs are located in the src directory of the installation directory:
Start redis service
$ cd src
$ ./redis-server
Copy after login
Note that starting redis in this way uses the default configuration. You can also tell redis to use the specified configuration file through startup parameters and use the following command to start.
$ cd src
$ ./redis-server redis.conf
Copy after login
redis.conf is a default configuration file. We can use our own configuration files if needed. After starting the redis service process, you can use the test client program redis-cli to interact with the redis service. For example:
[root@localhost src]$ ./redis-cli
127.0.0.1:6379> ping
PONG
Copy after login
Next modify redis.conf, set the password and background running mode.
$ vim /usr/local/redis/redis.conf
Copy after login
Remove the comment in front of
requirepass foobared
Copy after login
and change it to your password, such as
requirepass 123456
Copy after login
Change
daemonize yes
Copy after login
Copy after login
Copy after login
to
daemonize yes
Copy after login
Copy after login
Copy after login
Save it.
Configure redis service management script:
$ cp /usr/local/redis/utils/redis_init_script /etc/init.d/redis
Copy after login
Modify redis, vim /etc/init.d/redis
CONF="/usr/local/redis/redis.conf"
Copy after login
Start redis service
$ /etc/init.d/redis start
Starting Redis server...
12797:C 30 May 22:53:34.030 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
12797:C 30 May 22:53:34.030 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=12797, just started
12797:C 30 May 22:53:34.031 # Configuration loaded
Copy after login
At this time You can see that the redis service is up and occupies port 6739 by default.
Install PHP redis extension
Before starting to use Redis in PHP, we need to ensure that the redis service has been installed and that PHP can be used normally on your machine. Next, let us install the PHP redis driver. The download address is: https://github.com/phpredis/phpredis/releases.
Download and install the latest version:
$ wget https://github.com/phpredis/phpredis/archive/4.0.2.tar.gz
$ tar -zxvf phpredis-4.0.2.tar.gz
$ cd phpredis-4.0.2
$ /usr/local/php/bin/phpize # php安装后的路径
$ ./configure --with-php-config=/usr/local/php/bin/php-config
$ make && make install
Copy after login
Add redis.so to php.ini
$ echo 'extension=redis.so' >> /usr/local/php/etc/php.ini
Copy after login
Restart the php-fpm service
$ /etc/init.d/php-fpm restart
Copy after login
View redis Whether the extension is installed successfully
$ php -m | grep redis
redis
Copy after login
Test:
<?php
//连接本地的 Redis 服务
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->auth('123456');
echo "Connection to server sucessfully";
//查看服务是否运行
echo "Server is running: " . $redis->ping();
Copy after login
Currently, the PHP version installed in my system is 7.2. Experiments have proved that PHP7.2 already supports Redis.
If you execute phpize, you will get an error: Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.
Solution:
Installation Depends on autoconf
$ yum -y install autoconf
Copy after login
The above is the detailed content of How to install redis php extension on centos. For more information, please follow other related articles on the PHP Chinese website!