CentOS 7 Installation Php-redis extension and simple use

Source: Internet
Author: User
Tags redis cluster install redis

Objective:

In this article, I'm going to show you how to install Php-redis extensions on CentOS7 and some simple utilities on how to install Redis on CentOS, for reference

Redis installation Deployment on CentOS 7 http://www.linuxidc.com/Linux/2017-05/143312.htm

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

[linuxidc@localhost ~]# cd /usr/local/src[linuxidc@localhost src]# wget https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz

After the download is complete, unzip:

[linuxidc@localhost src]# tar -zxvf 2.2.4.tar.gz//进入解压后的目录[linuxidc@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

[linuxidc@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

[linuxidc@localhost phpredis-2.2.4]# make            #编译[linuxidc@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
[linuxidc@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/)

In the browser address bar, enter 127.0.0.1, view the PHP extension, if it is shown in the tablet, the installation is successful:

Step five: The simple use of Redis in PHP

In fact, Redis and MySQL are no different, the same database, (Redis is a non-relational database, MySQL is a relational database), so the use is similar, also has command line and PHP operation, on the command line of the Redis can be self-employed Baidu.

<?php$redis=New Redis ();Instantiating a Redis class$redisConnect (' 127.0.0.1 ',6379);//redis connection, here 127.0.0.1 is the local server, because the PHP file and the attached Redis database on a single host, 6379 is the default Redis port, you can omit the  $redis -> set (  ' name ',  ' Lsgogroup '); //set cache value  $redis -> Get (//get cache value  $reids -> Setex ( ' name ', 3600, ' Lsgogroup '); //set cache is worth 1 hours  $redis -> del (//manually delete the cache ?>        

The Redis command is much more than that, and it's just a simple use.

You may also like the following articles about Redis, as you can see below:

Ubuntu 14.04 Redis installation and simple test http://www.linuxidc.com/Linux/2014-05/101544.htm

Redis Master-slave replication basic configuration http://www.linuxidc.com/Linux/2015-03/115610.htm

Installation and configuration of Redis under CentOS 7 http://www.linuxidc.com/Linux/2017-02/140363.htm

Ubuntu 14.04 installation Redis with simple configuration http://www.linuxidc.com/Linux/2017-01/139075.htm

Install PHP7.0 redis extension http://www.linuxidc.com/Linux/2016-09/135631.htm in Ubuntu 16.04 environment

Redis Standalone & Cluster offline installation deployment http://www.linuxidc.com/Linux/2017-03/141403.htm

CentOS 7.0 Installation Redis 3.2.1 Detailed procedures and usage FAQs http://www.linuxidc.com/Linux/2016-09/135071.htm

Install PHP7.0 redis extension http://www.linuxidc.com/Linux/2016-09/135631.htm in Ubuntu 16.04 environment

Ubuntu 15.10 under Redis cluster deployment documentation http://www.linuxidc.com/Linux/2016-06/132340.htm

Redis Practical Chinese PDF http://www.linuxidc.com/Linux/2016-04/129932.htm

Redis Thermal Migration Combat summary http://www.linuxidc.com/Linux/2017-02/141083.htm

Redis3.0 configuration file http://www.linuxidc.com/Linux/2017-03/141369.htm

This article permanently updates the link address : http://www.linuxidc.com/Linux/2017-05/143316.htm

Reprint: https://www.linuxidc.com/Linux/2017-05/143316.htm

CentOS 7 Installation Php-redis extension and simple use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.