Home>Article>Backend Development> How to install redis php extension on centos
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 yesRedis 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 installAfter 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-serverNote 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.confredis.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 PONGNext modify redis.conf, set the password and background running mode.
$ vim /usr/local/redis/redis.confRemove the comment in front of
requirepass foobaredand change it to your password, such as
requirepass 123456Change
daemonize yesto
daemonize yesSave it. Configure redis service management script:
$ cp /usr/local/redis/utils/redis_init_script /etc/init.d/redisModify redis, vim /etc/init.d/redis
CONF="/usr/local/redis/redis.conf"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 loadedAt 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 installAdd redis.so to php.ini
$ echo 'extension=redis.so' >> /usr/local/php/etc/php.iniRestart the php-fpm service
$ /etc/init.d/php-fpm restartView redis Whether the extension is installed successfully
$ php -m | grep redis redisTest:
connect('127.0.0.1', 6379); $redis->auth('123456'); echo "Connection to server sucessfully"; //查看服务是否运行 echo "Server is running: " . $redis->ping();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
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!