Home > Article > Backend Development > Learn about installing redis extension for php7 in centos7
Recommended (free): PHP7
Download redis
Download redis, unzip and 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 #安装到指定目录
Now go to the source directory where the tar package was extracted just now, copy a redis.conf configuration file, and put it in / In the usr/local/redis/bin/ directory
##Enter the redis directory and run vi redis.conf
##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"
The above is to install the redis program
To enable the redis extension in php7
Use git clone to download git phpredis extension package
[root@localhost local ]#git clone https://github.com/phpredis/phpredis.gitAt this step, we need to use phpize generated when installing php to generate the configure configuration file,
//Specific Which one to use 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
这里表明路径为/usr/bin/phpize,然后执行:
[ 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.
这里报错了,原因是没有安装好php-devel,由于我是使用的php7.0所以执行以下命令:
[root@localhost phpredis]#yum -y install php70w-devel
然后再次执行:
[root@localhost phpredis]# /usr/bin/phpize Configuring for: PHP Api Version: 20151012 Zend Module Api No: 20151012 Zend Extension Api No: 320151012
执行完上一步,我们就有了 configure 配置文件了,接下来配置
[root@localhost phpredis]#./configure
或者执行
[root@localhost phpredis]#./configure --with-php-config=/usr/bin/php-config
接下来是编译安装
[root@localhost phpredis]#make [root@localhost phpredis]# make install Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/
配置php的配置文件php.ini(具体放在那里可以用 whereis php.ini 来查看),我的配置文件php.ini在/etc/下
[root@localhost phpredis]#vim /etc/php.ini
开启redis扩展:
extension = redis.so
redis.so文件的路径可以在make install的时候看到
[root@localhost local]# php -m #查询php的扩展
重启nginx服务器,重启php-fpm,使配置生效
重启之后我们打开info.php,已经可以看到redis的扩展信息了
更多相关学习推荐:PHP7教程
The above is the detailed content of Learn about installing redis extension for php7 in centos7. For more information, please follow other related articles on the PHP Chinese website!