23,LNMP架構

1, 什麼是LNMP
LNMP 是一套技術的組合, L=Linux、 N=Nginx、 M=MySQL、 P=PHP
2,LNMP工作流程
23,LNMP架構

原理:
1.用戶通過 http 協議發起請求,請求會先抵達 LNMP 架構中的 Nginx
2.Nginx 會根據用戶的請求進行判斷,這個判斷是有 Location 進行完成
3.判斷用戶請求的是靜態頁面, Nginx 直接進行處理
4.判斷用戶請求的是動態頁面, Nginx 會將該請求交給 fastcgi 協議下發
5.fastgi 會將請求交給 php-fpm 管理進程, php-fpm 管理進程接收到後會調用具體的工作進程 warrapr
6.warrap 進程會調用 php 程序進行解析,如果只是解析代碼 php 直接返回
7.如果有查詢數據庫操作,則由 php 連接數據庫(用戶 密碼 IP)發起查詢的操作
8.最終數據由 mysql->php->php-fpm->fastcgi->nginx->http->user
3,安裝LNMP
1,創建統一的用戶和組
groupadd www -g 666
useradd www -s /sbin/nologin -M -u 666 -g 666
2,下載nginxREPO源
wget http://nginx.org/packages/centos/$releasever/$basearch/
wget http://nginx.org/packages/mainline/centos/$releasever/$basearch/
yum -y install nginx
3,啓動並設置開機啓動nginx
systemctl start nginx
systemctl enable nginx
4,下載php7.1第三方源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

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

5,啓動並設置開機啓動PHP
systemctl start php-fpm
systemctl enable php-fpm
6,在Nginx和PHP配置文件的用戶修改爲www
sed -i '/^user/c user = www' /etc/php-fpm.d/www.conf
sed -i '/^group/c group = www' /etc/php-fpm.d/www.conf
7,安裝Mysql即Mariadb
yum install mariadb-server mariadb -y
8,啓動並設置開機啓動Mariadb
systemctl start mariadb
systemctl enable mariadb
9,數據庫配置賬號密碼
mysqladmin password 'oldboy123'(默認root密碼)
mysql -uroot -poldboy123 (登錄mysql)
使用指定IP登錄
mysql -uroot -poldboy123 -h127.0.0.1
show databases;
show tables from mysql;
select user,host from mysql.user;查看當前mysql有哪些用戶
desc user;查看錶字段
4,接通nginx和php即fastcgi

cat /etc/nginx/conf.d/php.conf
server {
    server_name www.oldboy.com;
    listen 80;
    root /code;
    index index.php index.html;

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

1,創建code目錄並做一個php測試網頁
mkdir /code
chown -R www:www /code/
cat /code/info.php

<?php
    phpinfo();
?>

2,nginx -t
systemctl restart nginx

3,網頁測試
23,LNMP架構

4,測試PHP和數據庫之間的連通性

cat /code/mysql.php 
<?php
    $servername = "localhost";
    $username = "root";
    $password = "oldboy123";

    // 創建連接
    $conn = mysqli_connect($servername, $username, $password);
    // // 檢測連接
    if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
    }
    echo "php 連接 MySQL 數據庫成功";
?>

瀏覽器上輸入:http://www.oldboy.com/mysql.php
23,LNMP架構
至此,Nginx與PHP接通,PHP與數據庫接通

5,部署Wordpress博客

1,配置wordpress虛擬主機
server {
    server_name blog.oldboy.com;
    listen 80;
    root /code/wordpress/;
    index index.php index.html;

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

2,重啓nginx
nginx -t
systemctl restart nginx

3,下載wordpress代碼壓縮包
cd /code
wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
tar -zxvf wordpress-4.9.4-zh_CN.tar.gz
chown -R www:www /code/wordpress

4,創建任意一個數據庫就叫wordpress
mysql -uroot -poldboy123
create database wordpress;
exit
5,瀏覽器訪問wordpress並部署
23,LNMP架構
23,LNMP架構
23,LNMP架構
23,LNMP架構
23,LNMP架構
以上編輯步驟後在PHP上生成/code/wopress/wp-config.php生成配置文件。用來接通數據庫
23,LNMP架構

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章