分布式部署LNMP+WordPress

安装Nginx

创建文件

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

编辑文件,添加以下内容

[nginx] 
name = nginx repo 
baseurl = https://nginx.org/packages/mainline/centos/7/$basearch/ 
gpgcheck = 0 
enabled = 1

退出保存

安装nginx

yum install -y nginx

打开文件

vi /etc/nginx/conf.d/default.conf

编辑文件,替换以下内容

用于取消对 IPv6 地址的监听,同时配置 Nginx,实现与 PHP 的联动。

server {
    listen       80;
    root   /usr/share/nginx/html;
    server_name  localhost;
    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;
    #
    location / {
          index index.php index.html index.htm;
    }
    #error_page  404              /404.html;
    #redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
      root   /usr/share/nginx/html;
    }
    #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ .php$ {
      fastcgi_pass   127.0.0.1:9000;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
      include        fastcgi_params;
    }
}

保存退出

启动nginx并设为开机自启动

systemctl start nginx
systemctl enable nginx

浏览器访问

http://虚拟机ip

在这里插入图片描述
显示安装成功

安装数据库

查看是否安装

rpm -qa | grep -i mariadb

显示以下内容说明已存在mariadb
在这里插入图片描述
为避免安装版本不同造成冲突,请执行以下命令移除已安装的 MariaDB。

yum -y remove 包名

若返回结果为空,则说明未预先安装,则执行下一步

创建文件

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

添加mariadb软件库

[mariadb]
name = MariaDB
baseurl = https://mirrors.cloud.tencent.com/mariadb/yum/10.4/centos7-amd64
gpgkey=https://mirrors.cloud.tencent.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1

保存退出

安装mariadb

yum -y install MariaDB MariaDB-server

启动并设为开机自启动

systemctl start mariadb
systemctl enable mariadb

验证是否安装成功

mysql

显示以下界面则安装成功
在这里插入图片描述
退出

安装配置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

安装所需包

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

启动php-fpm服务并设置开机自启动

systemctl start php-fpm
systemctl enable php-fpm

验证环境配置

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

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

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

systemctl restart nginx

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

http://虚拟机ip

显示结果如下, 则说明环境配置成功。
在这里插入图片描述

搭建WordPress

进入数据库修改配置

mysql -uroot -p000000
create database wordpress;
grant all privileges on *.* to “wordpress”@“localhost” identified by‘000000;
flush privileges;

重启服务

把wordpress压缩包上传到 /root文件夹下

systemctl restart nginx php-fpm mariadb
rm -rf /usr/share/nginx/html/*      //删除nginx默认文件
yum install -y unzip
unzip word press压缩包

解压

yum install -y unzip
unzip word press压缩包

部署

cp -rf wordpress/* /usr/share/nginx/html/
cd !$
ls

修改配置文件

cp wp-config-sample.php wp-config.php
vi wp-config.php
// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define('DB_NAME', 'wordpress');

/** MySQL数据库用户名 */
define('DB_USER', 'wordpress');

/** MySQL数据库密码 */
define('DB_PASSWORD', '000000');

/** MySQL主机 */
define('DB_HOST', 'localhost');

/** 创建数据表时默认的文字编码 */
define('DB_CHARSET', 'utf8');
chmod -R 777 /usr/share/nginx/html/
yum install -y net-tools
netstat -ntpl
curl localhost

测试

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值