kylin-LNMP架构的部署

LNMP架构

LNMP架构部署过程

部署准备

1.windows本地解析设置:
10.0.0.7	php.dezyan.com wp.dezyan.com shop.dezyan.com

2.统一运行所有服务的虚拟用户
[root@web01 ~]# groupadd -g 666 lnmp
[root@web01 ~]# useradd -g 666 -u 666 -M -s /sbin/nologin lnmp
[root@web01 ~]# id lnmp
uid=666(lnmp) gid=666(lnmp) groups=666(lnmp)

1.配置nginx服务

第一步:配置官网仓库
[root@web01 ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
第二步:安装nginx服务
[root@web01 ~]#  yum -y install nginx
第四步:修改nginx启动用户(统一用户lnmp)
[root@web01 ~]# vim /etc/nginx/nginx.conf 
  2 user  lnmp;
第五步:启动nginx服务
[root@web01 ~]# systemctl start nginx
[root@web01 ~]# systemctl enable nginx

2.配置PHP服务

第一步:安装PHP服务
[root@web01 ~]# yum -y install php php-bcmath php-cli php-common php-devel php-embedded php-fpm php-gd php-intl php-mbstring php-mysqlnd php-opcache php-pdo   php-process php-xml php-json
第二步:配置PHP服务,并检查配置文件代码语法
1.修改启动用户为lnmp
[root@web01 ~]# vim /etc/php-fpm.d/www.conf
24:user = lnmp
26:group = lnmp
2.修改监听方式
[root@web01 ~]# vim /etc/php-fpm.d/www.conf
 38 listen = 127.0.0.1:9000
[root@web01 ~]# php-fpm -t
第三步:启动PHP服务
[root@web01 ~]# systemctl start php-fpm
[root@web01 ~]# systemctl enable php-fpm
第四步:检查服务是否正常启动
[root@web01 ~]# ss -tnul
Netid State  Recv-Q Send-Q Local Address:Port  Peer Address:Port Process            
tcp   LISTEN 0      128        127.0.0.1:9000       0.0.0.0:*            

3.安装mariadb数据库

第一步:安装mariadb
[root@web01 ~]# yum install -y mariadb-server
第二步:启动mariadb服务
[root@web01 ~]# systemctl start mariadb
[root@web01 ~]# systemctl enable mariadb
第三步:配置数据库登录密码
[root@web01 ~]# mysqladmin password 'dzy123.com'
第四步:测试登录
[root@web01 ~]# mysql -uroot -pdzy123.com
Welcome to the MariaDB monitor.  Commands end with ; or \g.

4.配置nginx连接PHP

  • 编写配置文件打通与PHP的连接
[root@web01 ~]# vim /etc/nginx/conf.d/php.conf
server {
        listen 80;
        server_name php.dezyan.com;
        root /code;

        location / {
                index index.php index.html;
        }

        location ~ \.php$ {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
		include fastcgi_params;
        }
}
  • 写一个PHP文件,测试是否可以正常解析
[root@web01 ~]# vim /code/info.php
<?php
        phpinfo();
?>
  • 检查配置文件,重启nginx
[root@web01 ~]# nginx -t
[root@web01 ~]# systemctl restart nginx
  • 浏览器测试访问
http://php.dezyan.com/info.php
出现'PHP Version 7.2.34'则正常

5.测试PHP连接MySQL(可不做)

  • 在php的配置文件中写入数据库的IP+端口+用户名+密码可以测试是否连接数据库
[root@web01 ~]#  vim /code/mysql.php
<?php
    $servername = "localhost";
    $username = "root";
    $password = "dzy123.com";

    // 创建连接
    $conn = mysqli_connect($servername, $username, $password);

    // 检测连接
    if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
    }
    echo "链接失败!";
?>
<img style='width:100%;height:100%;' src=/mihayou1.jpg>
  • 浏览器访问测试
php.dezyan.com/mysql.php

6.部署wordpress业务

  • 创建nginx配置文件
[root@web01 ~]# vim /etc/nginx/conf.d/wp.conf
server {
        listen 80;
        server_name wp.dezyan.com;
        root /code/wordpress;

        location / {
                index index.php index.html;
        }

        location ~ \.php$ {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}
#测试代码文件
[root@web01 conf.d]# nginx -t
#重启nginx服务
[root@web01 conf.d]# systemctl restart nginx
  • 创建代码目录,下载代码并解压
[root@web01 conf.d]# mkdir /code/wordpress
[root@web01 conf.d]# cd /code/wordpress/
[root@web01 conf.d]# wget https://cn.wordpress.org/wordpress-5.0.3-zh_CN.tar.gz
[root@web01 conf.d]# tar xf wordpress-5.0.3-zh_CN.tar.gz
[root@web01 conf.d]# mv wordpress/* .
  • 修改代码目录属主属组为lnmp
[root@web01 conf.d]# chown -R lnmp.lnmp /code/wordpress/
  • 创建WordPress需要的数据库
[root@web01 ~]# mysql -uroot -pdzy123.com -e 'create database wordpress'
[root@web01 ~]# mysql -uroot -pdzy123.com -e 'show databases'
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| wordpress          |
+--------------------+
  • 访问业务
wp.dezyan.com
  • 网页提示填写内容根据事实填写即可

小tips:上传WordPress主题失败?

#当我们想上传WordPress主题时,会提示上传/安装失败,该如何解决?
#对于Nginx服务器,可以在nginx.conf文件中的http块内设置client_max_body_size参数。
http { 
	... 
	client_max_body_size 50m; # 设置最大请求体大小为 50 MB ... 
}

7.部署电商平台业务

  • 创建nginx配置文件
[root@web01 ~]# vim /etc/nginx/conf.d/shop.conf
server {
        listen 80;
        server_name shop.dezyan.com;
        root /code/shop;

        location / {
                index index.php index.html;
        }

        location ~ \.php$ {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}
#测试代码文件
[root@web01 conf.d]# nginx -t
#重启nginx服务
[root@web01 conf.d]# systemctl restart nginx
  • 创建代码目录,上传代码并解压,修改商城系统数据库配置文件
[root@web01 conf.d]# mkdir /code/shop
[root@web01 conf.d]# cd /code/shop/
上传
[root@web01 shop]# unzip phpshe1.8.zip
[root@web01 shop]# vim config.php
<?php
$pe['db_host'] = '127.0.0.1'; //数据库主机地址
$pe['db_name'] = 'sheshop'; //数据库名称
$pe['db_user'] = 'root'; //数据库用户名
$pe['db_pw'] = 'dzy123.com'; //数据库密码
$pe['db_coding'] = 'utf8';
$pe['url_model'] = 'pathinfo_safe'; //url模式,可选项(pathinfo/pathinfo_safe/php)
$pe['h5_host'] = ''; //手机版网址
define('dbpre','pe_'); //数据库表前缀
?>
  • 修改代码目录属主属组为lnmp
[root@web01 shop]# chown -R lnmp.lnmp /code/shop/
  • 创建shop需要的数据库
[root@web01 ~]# mysql -uroot -pdzy123.com -e 'create database sheshop'
[root@web01 ~]# mysql -uroot -pdzy123.com -e 'show databases'
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| wordpress          |
+--------------------+
  • 访问业务
shop.dezyan.com
posted @ 2025-03-21 08:42  丁志岩  阅读(26)  评论(0)    收藏  举报