linux cluster architecture -LNMP architecture

1. What is the architecture LNMP

How 2.LNMP architecture works

location / {
    index index.php;
}

location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
}

location ~ \.(jpg|png|gif)$ {
    root /code/images;
}

How to between 3.nginx and php, mysql works.

4. How to install LNMP architecture

Install php

Configure extended source

yum localinstall -y http://mirror.webtatic.com/yum/el7/webtatic-release.rpm

Installation php7.1

yum -y install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb

Start php

systemctl start php-fpm

Install mysql

touch /etc/yum.repos.d/mariadb.repo 
then write the following 
[MariaDB] 
name = MariaDB 
BaseURL = http://yum.mariadb.org/10.1/centos7-amd64 
gpgkey = HTTPS: //yum.mariadb .org / the RPM-the GPG-KEY-MariaDB 
gpgcheck. 1 =

installation

yum install mariadb-server mariadb -y

start up

systemctl start mariadb

5.nginx integrated with php principle

1. Write can parse the php nginx configuration file

[root@web01 conf.d]# cat php.oldxu.com.conf 
    server {
        listen 80;
        server_name php.oldxu.com;
        root /code;

        location / {
            index index.php;
        } 

        location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }

5.2. Write PHP code, access to test results.

[root@web01 conf.d]# cat /code/info.php
    <?php
        phpinfo();
    ?>

5.3host hijacking

6.php and mysql integration principle

6.1 Start the database

[root@web01 ~]# systemctl start mariadb

6.2. Configuration connection Password

[root@web01 ~]# mysqladmin password oldxu.com

6.3 Test Log mysql

[root@web01 ~]# mysql -uroot -poldxu.com
    MariaDB [(none)]>

6.4 php write code connecting to the database

[root @ web01 ~] # /code/mysqli.php
     <? PHP 
        $ ServerName = "localhost"; 
        $ username = "root"; 
        $ password = "oldxu.com"; 

        // create a connection 
        $ conn = mysqli_connect ($ servername , $ username, $ password); 

        // detect the connection 
        IF ($ conn) {! 
            Die ( "connection failed The:." mysqli_connect_error ()); 
        } 
        echo "PHP MySQL database connection success"; 
    ?>

6.5 Test

(. 1) [the root web01 @ ~] # PHP /code/mysqli.php
(2) may be a browser to test by way of

7. Deploy Wordpress, Wecenter, edusoho, phpmyadmin, ecshop by LNMP architecture,
7.1 cases
7.1.1. Writing Nginx integrated PHP configuration file (domain name and directory location defined site)

[root@web01 conf.d]# cat blog.oldxu.com.conf 
server {
    listen 80;
    server_name blog.oldxu.com;
    root /code/wordpress;

    location / {
        index index.php;
    }

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

7.1.2. According to Nginx configuration, initialization environment, and then upload the code

  

1. Prepare the site directory 
    [root @ web01 conf.d] # mkdir / code 

    2. Download wordpress Code 
    [root @ web01 conf.d] # cd / code 
    [root @ web01 code] # tar XF wordpress-5.2.3-zh_CN .tar.gz 

    3. create a database name 
    [root @ web01 code] # MySQL-uroot--poldxu.com 
    
    MariaDB [(none)]> the create database WordPress; 
    MariaDB [(none)]> Show databases; 
    + ----- + --------------- 
    | Database | 
    + -------------------- + 
    | information_schema | 
    | MySQL | 
    | performance_schema | 
    | the Test | 
    | WordPress | 
    + -------------------- + 
    5 rows in the SET (0.01 sec)


    4.统一Nginx  PHP的权限  为  www
    [root@web01 code]# groupadd www -g 666
    [root@web01 code]# useradd -u666 -g666 www
    
    [root@web01 code]# sed -i '/^user/c user www;' /etc/nginx/nginx.conf
    [root@web01 code]# chown -R www.www /code
    [root@web01 code]# systemctl restart nginx
    
    [root@web01 code]# sed -i '/^user/c user = www' /etc/php-fpm.d/www.conf 
    [root@web01 code]#  sed -i '/^group/c group = www' /etc/php-fpm.d/www.conf
    [root@web01 code]# systemctl restart php-fpm

7.2wecenter:

1. Write profile Nginx virtual host
[the root @ web01 the conf.d] CAT # zh.oldxu.com.conf
Server {
    the listen 80;
    server_name zh.oldxu.com;
    the root / code / ZH;

    client_max_body_size 100m;

    LOCATION / {
        the index.php index;
    }

    LOCATION ~ \ .php $ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $ $ DOCUMENT_ROOT fastcgi_script_name;
        the include fastcgi_params;
    }
}

2. upload codes, code changes the owner and group
[root @ web01 conf .d] # cd / code
[root @ web01 conf.d] # rz WeCenter_3-3-2.zip
[root @ web01 conf.d] # mkdir zh
[root @ web01 conf.d] # the unzip WeCenter_3-3-2 .zip -d / code / zh /
[root @ web01 code] # chown -R www.www / code


. 3. Create a library database login name
[root @ web01 code] # MySQL-uroot--poldxu.com

MariaDB [(none)]> the Create Database zh;
MariaDB [ (none)]> Show Databases;
+ -------------------- +
| Database |
+ ---------------- + ----
| information_schema |
| MySQL |
| performance_schema |
| the Test |
| WordPress |
| zh |
+ -------------------- +
6 rows in the SET ( sec 0.00)


3. restart Nginx service
[root @ web01 code] # systemctl restart nginx

4. configure host hijacking

7.3edusoho video site

配置文件
server {
    listen 80;
    server_name www.xxxx.com;
    root /code/edusoho/web;

    # 日志路径
    access_log /var/log/nginx/example.com.access.log;
    error_log /var/log/nginx/example.com.error.log;

    location / {
        index app.php;
        try_files $uri @rewriteapp;
    }

    location @rewriteapp {
        rewrite ^(.*)$ /app.php/$1 last;
    }

    location ~ ^/udisk {
        internal;
        root /code/edusoho/app/data/;
    }

    location ~ ^/(app|app_dev)\.php(/|$) {
        fastcgi_pass   127.0.0.1:9000;
        ^ fastcgi_split_path_info (/.*) $ (+ \ PHP..); 
    # Configure css / js file
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $ DOCUMENT_ROOT $ fastcgi_script_name; 
        fastcgi_param the HTTPS OFF; 
        fastcgi_param HTTP_X-Sendfile-the Type X--Accel-the Redirect; 
        fastcgi_param HTTP_X-Accel-the Mapping / udisk = / code / edusoho / App / Data / udisk; 
        fastcgi_buffer_size 128K; 
        fastcgi_buffers. 8 128K; 
    } 

    # set the format picture files 
    . LOCATION ~ * \ (JPG | jpeg | GIF | PNG | ico | SWF) $ { 
        # expiration of 3 years 
        the expires 3Y; 

        # Turn off logging 
        access_log OFF; 

        # close gzip compression, reducing CPU consumption, because the picture compression rate is not high. 
        OFF the gzip; 
    } 

    . ~ LOCATION * \ (CSS | JS) {$ 
        access_log OFF; 
        the Expires 3Y; 
    } 

    # prohibit users from uploading access to all .php files in the directory, improve security 
    LOCATION ~ ^ / Files /.* \ (PHP | php5) $ {. 
        deny All; 
    } 

    # the following configuration allows programs to run .php, facilitate the integration of third party systems. 
    ~ LOCATION \ .php $ { 
        # [modified] The edit mode of operation actual php-fpm 
        fastcgi_pass 127.0.0.1:9000; 
        fastcgi_split_path_info ^ (+ \ PHP..) (/.*) $; 
        the include fastcgi_params; 
        fastcgi_param $ SCRIPT_FILENAME fastcgi_script_name $ DOCUMENT_ROOT; 
        fastcgi_param the HTTPS OFF; 
    } 
}

 

Guess you like

Origin www.cnblogs.com/hh-y/p/11545984.html