实践一:LAMP-博客平台-WordPress

WordPress是一款个人博客系统,并逐步演化成一款内容管理系统软件,使用PHP语言和MySQL数据库 开发,用户可以在支持 PHP 和 MySQL 数据库的服务器上使用自己的博客。

官网 安装手册 下载

前提条件

用centos7模板克隆一台server

节点名称 节点IP 节点功能
wodpress 10.1.8.10/24 LAMP

基础配置

`
[root@server ~ 14:47:28]# bash
[root@wordpress ~ 14:47:35]# nmcli connection modify ens33 ipv4.method manual ipv4.addresses 10.1.8.10/24 ipv4.gateway 10.1.8.2 ipv4.dns 10.1.8.2 autoconnect yes
[root@wordpress ~ 14:48:30]# nmcli connection up ens33 
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/4)

`

准备好LAMP环境

`
# yum静默安装数据库、php环境、php扩展与apache(httpd)网站服务
[root@wordpress ~ 14:55:27]# yum install -y mariadb-server mariadb php php-fpm php-mysqlnd php-gd php-mbstring php-xml httpd
# 设置mariadb开机自启并立即启动服务
[root@wordpress ~ 15:05:26]# systemctl enable mariadb --now
# systemd创建mariadb开机自启动软链接输出信息
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
# 设置php-fpm开机自启并立即启动服务
[root@wordpress ~ 15:08:56]#  systemctl enable php-fpm --now
# systemd创建php-fpm开机自启动软链接输出信息
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
# 设置httpd(Apache)开机自启并立即启动服务
[root@wordpress ~ 15:09:21]#  systemctl enable httpd --now
# systemd创建httpd开机自启动软链接输出信息
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
`

准备数据库

`
# 初始化
# 执行MariaDB安全加固初始化脚本
[root@wordpress ~ 15:09:38]# mysql_secure_installation

# 脚本提示:生产环境推荐完整执行全部加固步骤,请仔细阅读每一步操作
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

# 脚本说明:登录数据库需要root当前密码,全新安装root默认无密码,直接回车
In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

# 输入root现有密码,首次部署直接回车
Enter current password for root (enter for none): 	# 【初次】 直接回车(默认无密码)
# 密码校验通过,继续执行后续步骤
OK, successfully used password, moving on...

# 脚本说明:设置root密码防止未授权访问root账号
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

# 确认是否设置root管理员密码
Set root password? [Y/n] y		# 输入 y → 设置 root 密码
# 输入自定义root密码
New password: 					#你要设置的密码,如huawei
# 重复输入密码确认
Re-enter new password: 			#再次输入密码
# root密码更新成功
Password updated successfully!
# 重载权限表
Reloading privilege tables..
 ... Success!

# 脚本说明:默认存在匿名测试账号,生产环境建议删除
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

# 是否删除匿名用户
Remove anonymous users? [Y/n] y		# 删除匿名用户(安全)
# 删除匿名用户执行成功
 ... Success!

# 脚本说明:限制root仅本地登录,避免网络暴力破解
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

# 是否禁止root远程登录
Disallow root login remotely? [Y/n] n	# 禁止远程登录root? (项目常用选 n; 安全服务器选 y)
# 跳过该配置项
 ... skipping.

# 脚本说明:内置test测试数据库,生产环境建议移除
By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

# 是否删除test测试库
Remove test database and access to it? [Y/n] y	# 删除 test 测试库
# 执行删除test数据库
 - Dropping test database...
 # 删除成功
 ... Success!
 # 回收test库相关权限
 - Removing privileges on test database...
 # 权限回收成功
 ... Success!

# 脚本说明:重载权限表使所有修改立即生效
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

# 是否立刻刷新权限表
Reload privilege tables now? [Y/n] y		# 刷新权限
# 权限重载成功
 ... Success!

# 执行清理操作
Cleaning up...

# 加固流程全部完成提示
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
# 软件致谢信息
Thanks for using MariaDB!

# 使用root账号登录MariaDB数据库
[root@wordpress ~ 15:10:43]# mysql -u root -p123
# MariaDB客户端欢迎信息
Welcome to the MariaDB monitor.  Commands end with ; or \g.
# 当前数据库连接编号
Your MariaDB connection id is 9
# 数据库服务端版本
Server version: 5.5.68-MariaDB MariaDB Server

# 版权信息
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

# 客户端帮助提示
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
# 创建wordpress网站业务数据库
MariaDB [(none)]> create database wordpress;
# 语句执行成功反馈
Query OK, 1 row affected (0.00 sec)

# 创建wordpress业务账号,仅允许本地访问
MariaDB [(none)]> create user wordpress@localhost identified by '123';
# 语句执行成功反馈
Query OK, 0 rows affected (0.00 sec)

# 将wordpress库所有权限授予wordpress本地账号
MariaDB [(none)]> grant all privileges on wordpress.* to wordpress@localhost;
# 语句执行成功反馈
Query OK, 0 rows affected (0.00 sec)

# 刷新权限,授权生效
MariaDB [(none)]> flush privileges;
# 语句执行成功反馈
Query OK, 0 rows affected (0.00 sec)

# 退出数据库客户端
MariaDB [(none)]> exit
# 客户端退出提示
Bye

`

准备WordPress

这里使用 wordpress-4.9.4 版本,该版本部署起来简单。

`
# 上传到root用户家目录
# 使用rz工具上传文件,-E参数防止覆盖同名文件
[root@wordpress ~ 15:15:20]# rz -E
# rz等待客户端发送文件提示
rz waiting to receive.
# 列出root家目录文件,确认wordpress压缩包上传成功
[root@wordpress ~ 15:16:39]# ls /root
anaconda-ks.cfg       wordpress-4.9.4-zh_CN.zip  模板  图片  下载  桌面
initial-setup-ks.cfg  公共                       视频  文档  音乐
# 解压wordpress中文源码压缩包
[root@wordpress ~ 15:16:49]# unzip wordpress-4.9.4-zh_CN.zip

# 递归复制wordpress网站源码到apache默认网站根目录
[root@wordpress ~ 15:17:04]# cp -aR wordpress /var/www/html/

# 递归修改wordpress目录归属为apache用户组,保障读写权限
[root@wordpress ~ 15:17:33]# chown -R apache:apache /var/www/html/wordpress/

# 重启apache(httpd)服务加载配置
[root@wordpress ~ 15:18:05]# systemctl restart httpd

`

配置过程

客户端登录 http://www.cyw.cloud/wordpress/

在这里插入图片描述

配置数据库

在这里插入图片描述

在这里插入图片描述

也可以使用以下方式配置后端数据库

`
# 设置WordPress后端数据库
# 切换工作目录至wordpress网站根目录
[root@wordpress ~]# cd /var/www/html/wordpress/
# 复制wp配置示例文件生成正式配置文件
[root@server wordpress]# cp wp-config-sample.php wp-config.php
# 使用vim编辑器编辑wordpress数据库配置文件
[root@server wordpress]# vim wp-config.php
# 更改如下四个参数:
# 定义WordPress所使用的数据库名称
/** WordPress数据库的名称 */
define('DB_NAME', 'wordpress');

# 定义连接数据库使用的账号
/** MySQL数据库用户名 */
define('DB_USER`, 'wordpress');

# 定义数据库账号对应的登录密码
/** MySQL数据库密码 */
define('DB_PASSWORD', 'huawei');

# 定义数据库服务所在地址
/** MySQL主机 */
define('DB_HOST', 'localhost');

# 定义数据库数据表前缀
/** WordPress数据表前缀 */
$table_prefix  = 'wp_';

`

如果出现下图信息:

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

设置目录权限,确保 apache 用户可以创建文件。

`
[root@wordpress ~]# chown -R 755 /var/www/html/wordpress/ 
`

配置网站

在这里插入图片描述

管理网站

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

#实践二:ECshop

ECshop介绍

官网

ECShop 多场景在线商城。

用centos7模板克隆一台server

ECshop部署

节点规划

节点名称 节点IP 节点功能
ecshop 10.1.8.10/24 LNMP
`
[root@server ~ 16:26:12]# hostnamectl set-hostname ecshop
[root@server ~ 16:29:16]# bash
[root@ecshop ~ 16:29:18]# nmcli connection modify ens33 ipv4.method manual ipv4.addresses 10.1.8.10/24 ipv4.gateway 10.1.8.2 ipv4.dns 10.1.8.2 autoconnect yes
[root@ecshop ~ 16:30:20]# nmcli connection up ens33 
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/4)

`

准备LNMP环境

准备nginx
`
# yum静默安装nginx服务
[root@ecshop ~ 16:31:22]# yum install -y nginx
# 设置nginx开机自启并且立即启动服务
[root@ecshop ~ 16:43:21]# systemctl enable nginx.service --now
# systemd创建自启动软链接的系统输出信息
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
# 覆盖nginx默认首页,写入测试文本
[root@ecshop ~ 16:44:02]# echo "Nginx Test Page" > /usr/share/nginx/html/index.html

`
准备Mariadb
`
# yum静默安装MariaDB数据库服务端
[root@ecshop ~ 16:44:57]# yum install -y mariadb-server
# 设置mariadb开机自启并立即启动服务
[root@ecshop ~ 16:46:06]# systemctl enable mariadb.service --now
# systemd生成开机自启动软链接的系统输出信息
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

# 安全初始化
# 执行MariaDB官方安全加固脚本
[root@ecshop ~ 16:46:29]# mysql_secure_installation

# 脚本提示:生产环境建议完整执行全部加固步骤,请仔细阅读每一步操作
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

# 脚本说明:需要root当前密码登录数据库进行加固,新装数据库root默认无密码,直接回车
In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

# 输入root现有密码,首次部署直接回车
Enter current password for root (enter for none):  # 【初次】 直接回车(默认无密码)
# 密码校验通过,继续下一步
OK, successfully used password, moving on...

# 脚本说明:设置root密码防止无授权人员登录root账号
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

# 确认是否设置root密码,输入y确认
Set root password? [Y/n] y	# 输入 y → 设置 root 密码
# 输入自定义root密码
New password: 				#你要设置的密码,如123
# 重复输入密码进行确认
Re-enter new password: 		#再次输入密码
# root密码更新成功
Password updated successfully!
# 重载权限表生效
Reloading privilege tables..
 ... Success!


# 脚本说明:默认存在匿名用户,仅用于测试,生产环境建议删除
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

# 是否删除匿名用户,输入y确认
Remove anonymous users? [Y/n] y		# 删除匿名用户(安全)
# 删除匿名用户操作执行成功
 ... Success!

# 脚本说明:默认root仅允许本地登录,防止外网暴力破解root密码
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

# 是否禁止root远程登录,本次选择n允许远程连接
Disallow root login remotely? [Y/n] n	# 禁止远程登录root? (项目常用选 n; 安全服务器选 y)
# 跳过该配置项
 ... skipping.

# 脚本说明:默认自带test测试库,任何人可访问,生产环境建议移除
By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

# 是否删除test测试数据库,输入y确认
Remove test database and access to it? [Y/n] y	# 删除 test 测试库
# 开始删除test库
 - Dropping test database...
# test库删除成功
 ... Success!
# 回收test库相关权限
 - Removing privileges on test database...
# 权限回收成功
 ... Success!

# 脚本说明:重载权限表使所有修改立刻生效
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

# 是否立即重载权限表,输入y确认
Reload privilege tables now? [Y/n] y	# 刷新权限
# 权限表重载成功
 ... Success!

# 执行收尾清理工作
Cleaning up...

# 全部加固流程完成提示
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
# 软件致谢信息
Thanks for using MariaDB!

`
准备PHP
`
# yum静默安装php环境与php-fpm进程管理程序
[root@ecshop ~ 16:47:40]# yum install -y php php-fpm

# 修改 php-fpm 运行用户身份
# 使用vim编辑器修改php-fpm站点配置文件
[root@ecshop ~ 16:50:28]# vim /etc/php-fpm.d/www.conf
# 更改以下两条记录
# user = apache
user = nginx

# group = apache
group = nginx

# 设置php-fpm开机自启并立即启动服务
[root@ecshop ~ 16:51:55]# systemctl enable php-fpm.service --now
# systemd生成开机自启动软链接的系统输出信息
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.

# 临时关闭防火墙服务
[root@ecshop ~ 16:52:36]# systemctl stop firewalld.service 

# 配置虚拟主机
# 复制nginx主配置文件作为虚拟主机配置模板
[root@ecshop ~ 16:53:02]# cp /etc/nginx/nginx.conf /etc/nginx/conf.d/vhost-shop.cyw.cloud.conf
# 使用vim编辑站点虚拟主机配置文件
[root@ecshop ~ 16:54:23]# vim /etc/nginx/conf.d/vhost-shop.cyw.cloud.conf
# 定义虚拟主机配置块
server {
    # 监听IPv4 80端口
    listen       80;
    # 监听IPv6 80端口
    listen       [::]:80;
    # 绑定访问域名
    server_name  shop.cyw.cloud;
    # 指定网站代码根目录
    root         /usr/share/nginx/html;
    
    # 设置默认主页
    index index.php;
    
    # 设置php页面处理方式
    # 匹配访问php后缀的请求
    location ~ \.php$ {
        # 校验php文件是否存在,不存在返回404
        try_files $uri =404;
        # 将php请求转发至本地php-fpm 9000端口处理
        fastcgi_pass 127.0.0.1:9000;
        # php默认首页文件
        fastcgi_index index.php;
        # 传递脚本物理路径参数给php-fpm
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    	# 引入fastcgi通用参数文件
    	include fastcgi_params;
    }
}

# 重启nginx服务加载最新虚拟主机配置
[root@ecshop ~ 17:06:32]# systemctl restart nginx

# 生成php测试页面用于验证nginx与php-fpm连通性
[root@ecshop ~ 17:08:47]# echo "<?php echo 'PHP Test Page'.\"\n\";?>" > /usr/share/nginx/html/test.php

`
客户端测试

在这里插入图片描述

准备数据库

`
# 使用root账号本地登录MariaDB数据库
[root@ecshop ~ 18:34:11]# mysql -u root -p123
# MariaDB客户端欢迎提示信息
Welcome to the MariaDB monitor.  Commands end with ; or \g.
# 当前数据库连接ID编号
Your MariaDB connection id is 11
# 数据库服务端版本信息
Server version: 5.5.68-MariaDB MariaDB Server

# 软件版权声明
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

# 客户端帮助提示说明
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
# 创建ecshop业务数据库
MariaDB [(none)]> create database ecshop;
# 语句执行成功提示
Query OK, 1 row affected (0.01 sec)

# 创建ecshop数据库账号,仅允许本地登录
MariaDB [(none)]> create user ecshop@localhost identified by '123';
# 语句执行成功提示
Query OK, 0 rows affected (0.00 sec)

# 将ecshop库全部权限授予ecshop本地账号
MariaDB [(none)]> grant all privileges on ecshop.* to ecshop@localhost;
# 语句执行成功提示
Query OK, 0 rows affected (0.00 sec)

# 刷新权限表,授权立即生效
MariaDB [(none)]> flush privileges;
# 语句执行成功提示
Query OK, 0 rows affected (0.00 sec)

# 退出MariaDB客户端
MariaDB [(none)]> exit
# 客户端退出提示
Bye

`

准备 ecshop 站点

准备 ecshop 站点数据文件,这里使用 ECShop_V4.1.20 版本。

``
# 上传到 root 用户家目录
# 使用rz工具接收上传文件,-E参数存在同名文件自动重命名
[root@ecshop ~ 18:36:56]# rz -E
# rz等待客户端传输文件提示
rz waiting to receive.
# 列出root家目录下所有文件,确认压缩包上传完成
[root@ecshop ~ 18:38:02]# ls /root
anaconda-ks.cfg          initial-setup-ks.cfg  模板  图片  下载  桌面
ECShop_V4.1.20_UTF8.zip  公共                  视频  文档  音乐
# 解压ECShop商城源码压缩包
[root@ecshop ~ 18:38:17]# unzip ECShop_V4.1.20_UTF8.zip 
# 将nginx默认网站根目录备份重命名
[root@ecshop ~ 18:38:54]# mv /usr/share/nginx/html/ /usr/share/nginx/html.ori
# 复制ecshop商城网站程序到nginx网站根目录
[root@ecshop ~ 18:40:09]# cp -a ECShop_V4.1.20_UTF8_release20250416/source/ecshop /usr/share/nginx/html
# 递归修改网站目录归属用户组为nginx,保障读写权限
[root@ecshop ~ 18:41:05]# chown -R nginx:nginx /usr/share/nginx/html

# 安装站点需要的各种扩展包
# yum静默安装ecshop所需的php相关扩展组件
[root@ecshop ~ 18:41:39]# yum install -y php-gd php-common php-pear php-mbstring php-mcrypt php-mysqlnd

# 修改php会话缓存目录权限归属nginx用户
[root@ecshop ~ 18:43:15]# chown -R nginx:nginx /var/lib/php/
# 重启nginx与php-fpm服务,加载新扩展与权限配置
[root@ecshop ~ 18:43:55]# systemctl restart nginx php-fpm

`

ECshop 配置

客户端登录 http://shop.cyw.cloud

勾选协议,点击 下一步:配置安装环境

在这里插入图片描述

点击 下一步:配置系统

在这里插入图片描述

页面上方出现的 Warning ,提示使用系统时区不安全,暂时忽略。

输入数据库账户信息后,点击,选中搜索到的数据库。

时区选择 亚洲,中国,上海,点击 立即安装

在这里插入图片描述

激活系统,享受更多服务。不激活也可以使用。关闭网页。

在这里插入图片描述

ECshop 访问

商城首页 http://shop.cyw.cloud

在这里插入图片描述

商城管理后台 http://shop.cyw.cloud/admin

在这里插入图片描述

使用ecshop账户登录

在这里插入图片描述

设置商店的一些基本信息

在这里插入图片描述

ECSHOP管理中心界面如下:

在这里插入图片描述

Logo

电商企业物流数字化转型必备!快递鸟 API 接口,72 小时快速完成物流系统集成。全流程实战1V1指导,营造开放的API技术生态圈。

更多推荐