Services - LNMP environment deployment

Posted by Heero on Fri, 21 Jan 2022 03:09:44 +0100

Article catalog

preface
I Introduction to LNMP
II What is fast CGI
III Deployment practice

  1. Install php and mysql
  2. The combination of nginx and php
    a. Compiling nginx
    b. Configure the combination of nginx and php
    c. Restart nginx for the configuration to take effect
    d. Configure index PHP test
    summary

preface

We have learned about the architecture, LAMP building, compilation and yum before. Today, we'll discuss the deployment of LNMP. We just replace apache with nginx, so it's relatively simple

I Introduction to LNMP

LNMP represents the website server architecture of Nginx+MySQL+PHP under Linux system.

  • Linux: we usually use redhat, centos and 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, which are combined to become a free, efficient and scalable website service system.

II What is fast CGI

Fast CGI is a scalable and high-speed interface for communication between HTTP server and dynamic scripting language. Most popular HTTP servers support fast CGI, including Apache, Nginx and lighttpd. At the same time, 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 is poor performance, because every time the HTTP server encounters a dynamic program, it needs to restart the script parser to execute the parsing, and then return the result to the HTTP server. This is almost unavailable when dealing with high concurrent access. In addition, the traditional CGI interface has poor security and is rarely used now
  
FastCGI interface adopts C/S structure, which can separate HTTP server and script parsing server, and start one or more script parsing daemons on the script parsing server at the same time. When the HTTP server encounters a dynamic program every time, it can directly deliver it to the fast CGI process for execution, and then return the obtained results to the browser. In this way, the HTTP server can specifically process static requests or return the results of the dynamic script server to the client, which greatly improves the performance of the whole application system.

III Deployment practice

1. Install php and mysql

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

2. The combination of nginx and php

a. Compiling nginx

The content of compilation has been written in the previous article. For details, please refer to:
[Linux] step by step learning operation and maintenance - service chapter - nginx introduction

yum -y install gcc gcc-c++ pcre-devel openssl-devel wget
[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
[root@gaosh-1 nginx-1.12.2]# ./configure --prefix=/usr/local/nginx
[root@gaosh-1 nginx-1.12.2]# make && make install
[root@gaosh-1 nginx-1.12.2]# ln -sv /usr/local/nginx/sbin/nginx /usr/bin/nginx
"/usr/bin/nginx" -> "/usr/local/nginx/sbin/nginx"
[root@gaosh-1 nginx-1.12.2]# nginx
b. Configure the combination of nginx and php

Text version of the picture 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;
        }


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 # starts PHP FPM
Starting PHP FPM: [OK]
[root@gaosh-1 ~]#

d. Configure 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();
?>

summary

The above is all about the deployment of LNMP architecture. In fact, it is easier than apache.

This article is from ID: Internet old Xin more content is concerned about the official account of the "geek operation and maintenance home".