WordPress网站-1·基于LNMP结构安装WordPres
2022-12-08 本文已影响0人
技术老男孩
一、基本环境准备:
虚拟机:一台
虚拟机IP地址:192.168.99.11
yum仓库:CentOS7.9
防火墙:关闭
主机名:web1
二、单击搭建流程思路:
- 配置nginx服务
- 配置数据库
- 部署wordpress
三、实操搭建:
第一步:配置nginx服务
- nginx安装及基本配置
# 安装依赖
[root@web1 ~]# yum -y install gcc openssl-devel pcre-devel
# 解压nginx软件包
[root@web1 lnmp_soft]# tar xf nginx-1.12.2.tar.gz
[root@web1 lnmp_soft]# cd nginx-1.12.2/
# 编译安装
[root@web1 nginx-1.12.2]# ./configure --with-http_ssl_module --with-http_stub_status_module
[root@web1 nginx-1.12.2]# make && make install
# 配置nginx服务
[root@web1 ~]# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=The Nginx HTTP Server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT ${MAINPID}
[Install]
WantedBy=multi-user.target
- 修改nginx配置文件,实现动静分离
# 修改nginx配置文件
[root@web1 ~]# vim /usr/local/nginx/conf/nginx.conf
... ...
# 设置index.php为默认打开页面
43 location / {
44 root html;
45 index index.php index.html index.htm;
46 }
... ...
# 配置支持php配置
65 location ~ \.php$ {
66 root html;
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_index index.php;
69 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_scri pt_name;
70 include fastcgi.conf;
71 }
# 重启服务
[root@web1 ~]# systemctl restart nginx
- php、mariadb安装及启动服务
# 安装数据库、php软件包
# mariadb-server mariadb-devel php php-fpm php-mysql
[root@web1 ~]# yum install -y mariadb-server mariadb-devel php php-fpm php-mysql
# 配置服务
# mariadb数据库服务(端口3306)
[root@web1 ~]# systemctl enable mariadb.service --now
[root@web1 ~]# ss -tlnp | grep :3306
LISTEN 0 50 *:3306
# php-fpm服务,处理php动态程序(端口9000)
[root@web1 ~]# systemctl enable php-fpm.service --now
[root@web1 ~]# ss -tlnp | grep :9000
LISTEN 0 128 127.0.0.1:9000
- 相关日志位置:/usr/local/nginx/logs和/var/log/php-fpm/目录
- 测试对php的支持
# 撰写一个php页面
[root@web1 ~]# vim /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
浏览器访问http://192.168.99.11/查看结果,如果可以看到php信息的网页,则正确。如下:

第二步:配置Mariadb数据库
- 创建数据库
# 进入数据库
[root@web1 ~]# mysql
# 创建名为wordpress的数据库
# 字符编码采用utf8mb4
MariaDB [(none)]> create database wordpress character set utf8mb4;
- 授权用户访问数据库
# 创建名为wordpress的用户,登录密码也是wordpress
# 该可以对wordpress拥有全部权限
# 该用户既可以在本机登录,也可以在其他客户端地址登录。
MariaDB [(none)]> grant all on wordpress.* to wordpress@'localhost' identified by 'wordpress';
MariaDB [(none)]> grant all on wordpress.* to wordpress@'192.168.99.11' identified by 'wordpress';
MariaDB [(none)]> grant all on wordpress.* to wordpress@'%' identified by 'wordpress';
# 刷新权限
MariaDB [(none)]> flush privileges;
- 测试账号连接数据库
# -u 指定数据库账户名称
# -p 指定数据库账户的密码
# -h 指定需要远程数据库的IP地址
# 最后的“wordpress”是数据库的名称
[root@web1 ~]# mysql -uwordpress -pwordpress -h192.168.99.11 wordpress
第三步:部署wordpress
- 复制源码包到nginx的工作目录
# 进入源码包(资料包)
[root@web1 ~]# cd lnmp_soft/
# 安装解压工具
[root@web1 lnmp_soft]# yum install -y unzip
# 解压
[root@web1 lnmp_soft]# unzip wordpress.zip
[root@web1 lnmp_soft]# cd wordpress/
[root@web1 wordpress]# tar xf wordpress-5.0.3-zh_CN.tar.gz
[root@web1 wordpress]# cd wordpress/
# 复制源码内容到nginx的html目录下
[root@web1 wordpress]# cp -r * /usr/local/nginx/html/
- 修改html目录权限
# 由于php程序是由php-fpm处理的
# 可以看到php-fpm是以apache身份运行
[root@web1 wordpress]# ps aux | grep php-fpm
root 3916 0.0 0.5 330192 10260 ? Ss 17:30 0:00 php-fpm: master process (/etc/php-fpm.conf)
apache 3956 0.0 1.8 361776 37044 ? S 17:30 0:05 php-fpm: pool www
apache 3957 0.0 1.7 360468 35716 ? S 17:30 0:05 php-fpm: pool www
apache 3958 0.0 1.7 359060 34748 ? S 17:30 0:05 php-fpm: pool www
apache 3959 0.0 1.6 358428 33708 ? S 17:30 0:05 php-fpm: pool www
apache 3960 0.0 1.8 360992 36256 ? S 17:30 0:06 php-fpm: pool www
apache 4433 0.0 1.7 360600 35880 ? S 17:55 0:05 php-fpm: pool www
apache 4465 0.0 2.1 368156 43372 ? S 17:58 0:04 php-fpm: pool www
apache 5178 0.0 1.7 360212 35244 ? S 19:11 0:01 php-fpm: pool www
root 5330 0.0 0.0 112824 976 pts/0 S+ 19:58 0:00 grep --color=auto php-fpm
# 为了让php-fpm程序能对html目录进行读写操作
# 需要为他授予权限
[root@web1 wordpress]# chown -R apache:apache /usr/local/nginx/html
-
访问http://192.168.99.11/readme.html可以查阅wordpress使用说明
-
访问http://192.168.99.11/进行初始化,它将自动跳转到http://192.168.99.11/wp-admin/setup-config.php
初始化.png
-
将服务器上的数据库信息填入
配置数据库.png
安装.png
-
配置站点信息和登录密码
安装Wordpress.png
登录1.png
登录2.png
管理页面.png
-
访问192.168.99.11查看前台页面,出现以下页面则搭建完成
前台页面.png