Objective:
In this blog, I will show you how to install the Php-redis extension on Centos7 and some simple and useful information on how to install Redis on CentOS, refer to my previous blog about Redis's installation deployment on CENTOS7
If you want to operate Redis in PHP, you must install the Php-redis extension, like MySQL, if PHP wants to operate the MySQL database, you must install the MySQL extension, but the default is to install the MySQL extension in the PHP installation.
Step one: Download unzip
Download: https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz
We put the source package in a specific directory is a good habit, and now I put the source package in the/usr/local/src inside
[lsgozj@localhost ~]# cd /usr/local/src[lsgozj@localhost src]# wget https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz
After the download is complete, unzip:
[lsgozj@localhost src]# tar -zxvf 2.2.4.tar.gz//进入解压后的目录[lsgozj@localhost src]# cd phpredis-2.2.4
Step two: Compile and install
1, to this step, we want to use the phpize generated when installing PHP to generate the Configure configuration file
[[email protected] phpredis-2.2.4]# /usr/local/php/bin/phpize (或 /usr/bin/phpize) //具体用哪个要取决于你的phpize文件所在的目录,这时你应该用 whereis phpize 来查看路径
After performing the previous step, we have the Configure configuration file.
2. Configuration
[lsgozj@localhost phpredis-2.2.4]# ./configure --with-php-config=/usr/local/php/bin/php-config #配置
Where Php-config and Phpize are located in the same directory, such as above I use/usr/bin/phpize, then in this step I use./configure–with-php-config=/usr/bin/php-config (In fact, if your PHP is the default installation path, directly./configure on it, personally)
3. Compile and install
[lsgozj@localhost phpredis-2.2.4]# make #编译[lsgozj@localhost phpredis-2.2.4]# make install #安装
Step Three: Configure PHP support
Configure PHP configuration file php.ini (where it can be viewed with Whereis php.ini), my profile php.ini under/etc/
[[email protected] phpredis-2.2.4]# vim /etc/php.ini//编辑php.ini,在最后一行(或者搜索extension_dir所在行的下一行,这样把扩展配置放在一起是个好习惯嘛)添加一下内容extension="redis.so"
Save exit
Step four: Restart the Apache server for the configuration to take effect
[lsgozj@localhost phpredis-2.2.4]# systemctl restart httpd.service
After restarting, check whether the installation is complete Php-redis extension
[[email protected] phpredis-2.2.4]# echo "<?php echo phpinfo() ?>">>/home/www/index.php(这里web目录如果没改的话是在 /var/www/html/)
Enter 127.0.0.1/index.php in the browser address bar to view the PHP extension and, if there is a Redis, the installation is successful:
Centos7 Installing Php-redis Extensions