分布式部署LNMP+Wordpress

步骤一:安装 Nginx

1.执行以下命令,在 /etc/yum.repos.d/ 下创建 nginx.repo 文件。

vi /etc/yum.repos.d/nginx.repo

2.按 i 切换至编辑模式,写入以下内容

 

 3.按 Esc,输入 :wq,保存文件并返回。

 4.执行以下命令,安装 nginx。

yum install -y nginx

5.执行以下命令,打开 default.conf 文件。

vim /etc/nginx/conf.d/default.conf

 

 

 

 

8. 按 Esc,输入 :wq,保存文件并返回。

9.执行以下命令启动 Nginx。

systemctl start nginx

10.执行以下命令,设置 Nginx 为开机自启动。

systemctl enable nginx

11.在本地浏览器中访问地址,查看 Nginx 服务是否正常运行

 

 

步骤二:安装数据库

1.执行以下命令,查看系统中是否已安装 MariaDB。

rpm -qa | grep -i mariadb

返回结果类似如下内容,则表示已存在 MariaDB

 

 为避免安装版本不同造成冲突,请执行以下命令移除已安装的 MariaDB。

 yum -y remove 包名
 
若返回结果为空,则说明未预先安装,则执行下一步
 
2.执行以下命令,在 /etc/yum.repos.d/ 下创建 MariaDB.repo 文件。
vi /etc/yum.repos.d/MariaDB.repo
 
3.按 i 切换至编辑模式,写入以下内容,添加 MariaDB 软件库。

 

4.按 Esc,输入 :wq,保存文件并返回。

 

 5.执行以下命令,安装 MariaDB。此步骤耗时较长,请关注安装进度,等待安装完毕。

yum -y install MariaDB-client MariaDB-server

6.执行以下命令,启动 MariaDB 服务。

systemctl start mariadb

7.执行以下命令,设置 MariaDB 为开机自启动。

systemctl enable mariadb

8.执行以下命令,验证 MariaDB 是否安装成功。

mysql

显示结果如下,则成功安装。

 

 9.执行以下命令,退出 MariaDB。

步骤三:安装配置 PHP

1.依次执行以下命令,更新 yum 中 PHP 的软件源。

rpm -Uvh https://mirrors.cloud.tencent.com/epel/epel-release-latest-7.noarch.rpm

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

2.执行以下命令,安装 PHP 7.2 所需要的包。

yum -y install mod_php72w.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-mysqlnd php72w-fpm.x86_64

3.执行以下命令,启动 PHP-FPM 服务。

systemctl start php-fpm

4.执行以下命令,设置 PHP-FPM 服务为开机自启动。

systemctl enable php-fpm

验证环境配置

1.执行以下命令,创建测试文件。

echo "<?php phpinfo(); ?>" >> /usr/share/nginx/html/index.php

2.执行以下命令,重启 Nginx 服务。

systemctl restart nginx

3.在本地浏览器中访问如下地址,查看环境配置是否成功。

显示结果如下, 则说明环境配置成功。

 

 yum源已经配好lnmp和centos

[root@xserver1 ~]# yum repolist

 

 # mariadb-server已经安装并且初始化,否则也要安装并且初始化。

[root@xserver1 ~]# yum install -y nginx php-fpm php-mysql

 

 # 配置php

[root@xserver1 ~]# vim /etc/php-fpm.d/www.conf

进入修改以下内容

 

 [root@xserver1 ~]# vim /etc/nginx/conf.d/default.conf 

# 配置nginx 

 

 

 

 [root@xserver1 ~]# mysql -uroot -p123456

Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.44-MariaDB-log MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all privileges on *.* to "wordpress"@"localhost" identified by '000000';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

# 重启服务

[root@xserver1 ~]# systemctl restart nginx php-fpm mariadb

# 删除nginx默认文件

[root@xserver1 ~]# rm -rf /usr/share/nginx/html/*

# 解压

[root@xserver1 ~]# yum install -y unzip
[root@xserver1 ~]# unzip wordpress-4.

 #部署

[root@xserver1 ~]# cp -rf wordpress/* /usr/share/nginx/html/

[root@xserver1 ~]# cd !$

cd /usr/shazre/nginx/html/

#修改配置文件,根据mysql授权信息填写配置文件

[root@xserver1 ~]# cp wp-config-sample.php wp-config.php

[root@xserver1 ~]# vim wp-config.php

 

 [root@xserver1 html]# chmod -R 777 /usr/share/nginx/html/

[root@xserver1 html]# netstat -ntpl

[root@xserver1  heml]# curl localhost

 

 

 

 

posted @ 2021-12-09 14:58  小yi不闹  阅读(183)  评论(0编辑  收藏  举报