Ubuntu16.04 under Nginx+mysql+php+redis

Source: Internet
Author: User
Tags fpm redis redis server

I. Introduction of Redis
Redis is a key-value storage system. Similar to memcached, data is cached in memory in order to ensure efficiency. The difference is that Redis periodically writes the updated data to disk or writes the modified operation to the appended record file, and Master-slave (Master-Slave) synchronization is implemented on this basis. In some cases can be a good complement to the relational database. It provides java,c/c++ (Hiredis), C#,php,javascript,perl,object-c,python,ruby and other clients, which is convenient to use.

Second, the structure diagram

The approximate structure is read-write separation, synchronizing data from MySQL to Redis via triggers

Third, installation LNMP environment

1.apt-get Installation

install nginx mysql-server php

2. config nginx, support PHP

 vi /etc/nginx/sites-available/default ... # Pass the PHP scripts to FastCGI server listening on  127.0 . 0.1 : 9000   #location  ~ \.php$ {incloude snippets /fastcgi- php.conf;## # with PHP7.  0 -cgi alone;# fastcgi_pass  127.0 . 0.1 : 9000  ; # # with PHP7.     0 -FPM; Fastcgi_pass Unix: /run/php/php7. 0 -fpm.sock;} ......

3. Restart Nginx, test

vi /var/www/html/info.php<?php phpinfo ();? >

Then visit the page to see the information about PHP, the basic environment even if the building is complete.

Iv. installation of Redis

1. Installing Redis extensions for Redis and PHP

Install redis-serveraptInstall-B php7 https://github.com/ Phpredis/phpredis.gitcd phpredis/phpize. /Configuremake doinstall

2. Configure the Redis extension for PHP

VI /etc/php/7.0/fpm/conf.d/redis.iniextension=redis.so

3. Restart FPM and visit info.php to see the redis extension

/ETC/INIT.D/PHP7. 0-fpm Restart

Five, read the test

<?PHP//Connect to local Redis service$redis=NewRedis (); $redis->connect (' localhost ', ' 6379 ') or die("Could net connect redis server!");//$redis->auth (' admin123 ');//login authentication password, return "true | false"$redis->ping ();//Check to see if the link is back, [+pong]  $redis->select (0);//Select Redis Library, 0~15 a total of 16 libraries//Setup Data$redis->set (' School ', ' Wuruan '); //setting up multiple data$redis->mset (Array(' name ' = ' Jack ', ' age ' =>24, ' height ' = ' 1.78 ')); //storing data in a list$redis->lpush ("Tutorial-list", "Redis"); $redis->lpush ("Tutorial-list", "Mongodb"); $redis->lpush ("Tutorial-list", "Mysql"); //get stored data and outputEcho $redis->get (' School '); 
Echo ' <br/> ';
$gets=$redis->mget (Array(' name ', ' age ', ' height '));
Print_r($gets);
echo ' <br/> '; $tl=$redis->lrange ("Tutorial-list", 0, 5); Print_r($tl);
echo ' <br/> '; //Freeing Resources$redis-close ();?>

Ubuntu16.04 under Nginx+mysql+php+redis

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.