CENTOS7 installation Php-redis expansion and simple use

Source: Internet
Author: User
Tags install php pack delete cache install redis
Preface:

In this blog, I will show you how to install Php-redis extensions on CENTOS7 and some simple and practical, about how to install Redis on CentOS, you can refer to my previous blog Redis installation deployment on CENTOS7

Want to operate Redis in PHP, that must install Php-redis extension, like MySQL, PHP want to operate MySQL database, you must install MySQL extension, only in the PHP installation of the default installed MySQL extension. Step one: Download decompression

Download: https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz
It's a good habit to put the source pack in a specific directory, and now I put the source pack in the/USR/LOCAL/SRC.

[Lsgozj@localhost ~]# cd/usr/local/src
[lsgozj@localhost src]# wget Archive/2.2.4.tar.gz

After downloading, unpack:

[Lsgozj@localhost src]# TAR-ZXVF 2.2.4.tar.gz
//into the unpacked directory
[lsgozj@localhost src]# CD phpredis-2.2.4
Step Two: Compile the installation

1. In this step, we will use the phpize generated when installing PHP to generate the Configure configuration file

[Lsgozj@localhost phpredis-2.2.4]#/usr/local/php/bin/phpize (or/usr/bin/phpize) 

When we finish 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 the same directory, such as the 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, direct./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 the PHP configuration file php.ini (where it can be viewed with Whereis php.ini), my profile php.ini under/etc/

[Lsgozj@localhost phpredis-2.2.4]# Vim/etc/php.ini
//Edit php.ini, on the last line (or on the next line of the row where the Extension_dir is located, It's a good habit to put the extended configuration together. Add Content
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 the reboot, check to see if the installation completes the Php-redis extension

[Lsgozj@localhost phpredis-2.2.4]# Echo <?php echo phpinfo ()?> ">>/home/www/index.php" (here the Web directory if not changed is in/ var/www/html/)

Enter 127.0.0.1 in the browser address bar to view the PHP extension, which indicates that the installation was successful if the following picture shows:
Step Five: The simple use of Redis in PHP

In fact, Redis and MySQL is no different, the same is the database, (Redis database, MySQL is relational database), so use is similar, the same command line with the use of PHP operations, on the Redis of the form of the command line you can own Baidu.

<?php

    $redis = new Redis ()//Instantiate Redis class
    $redis-> connect (' 127.0.0.1 ', 6379); Here 127.0.0.1 is the local server, because the PHP file and the Redis database are on the same host, 6379 is the Redis default port, you can omit
    $redis-> set (' Name ', ' Lsgogroup '); Sets the cache value
    $redis-> get (' name ');//Gets
    The cached value $reids-> setex (' name ', 3600, ' lsgogroup ');/set cache time is worth 1 hours
    $ Redis-> del (' name ');//manually delete cache

?>

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

Disclaimer: Since the beginning of this blog is not very beginning, so the reference to a few online blog and mu-class network, here will no longer give the original address.

Related Article

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.