Hello everyone, I am Internet old xin, this is my 28th day to participate in the more wen Challenge, the activity details: more Wen Challenge

preface

Before, we learned about LAMP construction, compilation and YUM. Today, we will discuss the deployment of LNMP. LNMP is a relatively common underlying architecture.

I. Introduction of LNMP

LNMP is composed of three parts: Nginx+MySQL+PHP web server architecture under Linux system.

  • Linux: we generally use redhat, centos, ubuntu
  • Nginx is a high-performance HTTP and reverse proxy server, as well as an IMAP/POP3/SMTP proxy server.
  • Mysql is a small relational database management system.
  • PHP is a scripting language embedded in HTML documents executed on the server side.

These four kinds of software are free and open source software, combined together, become a free, efficient, extensible website service system.

What is fast-CGI

Fast-cgi is a scalable, high-speed interface for communication between HTTP Server and dynamic scripting languages. Fast-cgi is supported by most popular HTTP servers, including Apache, Nginx, and Lighttpd. Fast-cgi is also supported by many scripting languages, including PHP.

Fast-CGI is developed and improved from CGI. The main disadvantage of the traditional CGI interface approach is poor performance, because every time the HTTP server encounters a dynamic program, it needs to restart the script parser to perform the parsing and then return the results to the HTTP server. This is almost unavailable when dealing with high concurrent access. In addition, the traditional CGI interface is also very poor security, now has rarely used the FastCGI interface using C/S structure, you can separate the HTTP server and script parsing server, and start one or more script parsing daemons on the script parsing server. Each time the HTTP server encounters a dynamic program, it can deliver it directly to the fast-CGI process for execution, and then return the results to the browser. This approach allows the HTTP server to exclusively handle static requests or return the results of the dynamic script server to the client, greatly improving the overall performance of the application system.

Deployment of actual combat

1. Install PHP and mysql

[root@gaosh-1 ~]# cat /etc/redhat-release 
CentOS release 6.9 (Final)
[root@gaosh-1 ~]# 
Copy the code
[root@gaosh-1 ~]# yum install mysql mysql-server php php-mysql php-fpm
Copy the code

2. Nginx combined with PHP

A. compilation nginx

In this case, we are using nginx version 1.12.2, which can be downloaded from the official website

yum -y install gcc gcc-c++ pcre-devel openssl-devel wget
Copy the code
[root@gaosh-1 ~]Wget # http://nginx.org/download/nginx-1.12.2.tar.gz
[root@gaosh-1 ~]# tar xf nginx - 1.12.2. Tar. Gz
[root@gaosh-1 ~]# CD nginx - 1.12.2[nginx root @ gaosh - 1-1.12.2]# ./configure --prefix=/usr/local/nginx[nginx root @ gaosh - 1-1.12.2]# make && make install
Copy the code
[nginx root @ gaosh - 1-1.12.2]# ln -sv /usr/local/nginx/sbin/nginx /usr/bin/nginx
"/usr/bin/nginx" -> "/usr/local/nginx/sbin/nginx"[nginx root @ gaosh - 1-1.12.2]# nginx
Copy the code
B. Configure nginx to work with PHP

Text version of the image above:


        server {
        listen       80;
        server_name  localhost;

        location / {
            root   /www/zmgaosh;
            index index.php  index.html index.htm;
        }


        location ~ \.php$ {
               root          /www/zmgaosh;
               fastcgi_pass   127.0.0.1:9000;
               fastcgi_index  index.php;
               fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
               include       fastcgi_params;
        }


Copy the code
C. Restart nginx for the configuration to take effect

[root@gaosh-1 ~]# /usr/local/nginx/sbin/nginx -s stop [root@gaosh-1 ~]# nginx

[root@gaosh-1 ~]# /etc/init.d/php-fpm start # FPM: [root@gaosh-1 ~]#

D. Configure the index. PHP test

[root@gaosh-1 ~]# mkdir -p /www/zmgaosh
[root@gaosh-1 ~]# vim /www/zmgaosh/index.php
[root@gaosh-1 ~]# cat ! $cat /www/zmgaosh/index.php <? php phpinfo(); ? >Copy the code

The PHP page shown in the figure shows that it is installed, and you can install your desired front-end templates on it.

conclusion

That’s all it takes to deploy the LNMP architecture, which is actually a little easier than Apache.