CentOS8.5.2111(8)LAMP部署综合实验

一、实验目标

1.理解Apache服务器原理

2.掌握Apache服务器的配置文件

3.具备安装Mysql数据库能力

4.具备安装Apache服务器能力

5.具备PHP与数据库连接能力

6.具备Apache、Mysql、PHP的故障排除能力

二、实验拓扑

图8- 1

四台虚拟机按拓扑图搭建,准备好网络连接,每台Linux要架设好yum源(本地或Ali云均可)。

三、实训原理/流程

LAMP介绍

LAMP是由Linux, Apache, MySQL, PHP组成的,即把Apache、MySQL以及PHP安装在Linux系统上,组成一个环境来运行PHP的脚本语言。Apache是最常用的Web服务软件,而MySQL是比较小型的数据库软件。三个角色可以安装在一台机器上,也可以分开(但httpd和php要在一起的)

图8- 2

为什么需要LAMP?

手动逐个编译安装各个组件,需要输入各种命令,且有可能会中途出错。对于想要成功搭建 LAMP 建站环境来说,可以节约大量时间和精力。

LAMP 有什么优点?

LAMP 是最经典的建站环境之一,风靡世界十几年。而本脚本只需几个简单交互,选择需要安装的包,即可一路安装,无人值守。

1)项目背景 (以下所有配置以巫正中/wzz.cqie为实例,自行校正)

某企业的网络技术员,需发布搭建WEB服务对公司的文化、产品进行宣传。本次实验任务是实现基于Centos环境下Apache服务、Mysql数据与后台开发程序PHP的接口。(IP根据自己实际配置自行校正)

表8-1 实验主机规划

|---------|-------------------|--------------------|
| 主 机 名 称 | 操作系统 | IP地址 |
| www | CentOS8 | 192.168.学号.71(自己定) |
| Client1 | CentOS8 | 192.168.学号.73(自己定) |
| Client2 | windows server 12 | 192.168.学号.25(自己定) |

2)任务要求:

1.安装并配置mysql数据库;

2.安装Apache服务;

3.安装PHP及相关组件;

4.客户端验证测试。

3)实验步骤:

重要提示:请确保虚拟机能正常连接到互联网!!!测试虚拟机是否连接互联网

|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| root@www \~# ping www.baidu.com -c 2 PING www.a.shifen.com (183.2.172.42) 56(84) bytes of data. 64 bytes from 183.2.172.42 (183.2.172.42): icmp_seq=1 ttl=128 time=48.3 ms 64 bytes from 183.2.172.42 (183.2.172.42): icmp_seq=2 ttl=128 time=42.1 ms |

(1)关闭防火墙

|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| root@www \~# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2024-11-22 22:12:48 EST; 4h 14min ago Docs: man:firewalld(1) Main PID: 983 (firewalld) Tasks: 2 (limit: 4329) Memory: 38.2M CGroup: /system.slice/firewalld.service └─983 /usr/libexec/platform-python -s /usr/sbin/firewalld --nofork --nopid 11月 22 22:12:47 www systemd1: Starting firewalld - dynamic firewall daemon... 11月 22 22:12:48 www systemd1: Started firewalld - dynamic firewall daemon. 11月 22 22:12:48 www firewalld983: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will be r> root@www \~# systemctl stop firewalld |

(2)关闭selinux

|-----------------------------------------|
| root@www \~# vi /etc/selinux/config |

|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of these three values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted |

(3)重启设备并输入Sestatus查看状态

|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| root@www \~# sestatus SELinux status: enabled SELinuxfs mount: /sys/fs/selinux SELinux root directory: /etc/selinux Loaded policy name: targeted Current mode: enforcing Mode from config file: disabled Policy MLS status: enabled Policy deny_unknown status: allowed Memory protection checking: actual (secure) Max kernel policy version: 33 |

或getenforce

|---------------------------------------|
| root@www \~# getenforce Enforcing |

重启reboot

(4)安装MySQL

//*说明:在Centos 8 环境可以忽略此步骤, 如果有冲突,才安装兼容性更好的5.7版本)*

//*编辑mysql仓库,启用5.7版本仓库,其他版本禁用。(最新版8.0变化比较大,增加了一些关键字,可能和老软件不兼容,特别是后期与openstack云平台不兼容)

a.创建版本仓库repo文件

|----------------------------------------------------------------------------------------|
| root@www \~# cd /etc/yum.repos.d root@www yum.repos.d# vi mysql-community.repo |

|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| # Enable to use MySQL 5.7 mysql57-community name=MySQL 5.7 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/ enabled=1 gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql mysql80-community name=MySQL 8.0 Community Server baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql |

b.建立元数据库

|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| root@www \~# makecache -bash: makecache: 未找到命令 root@www \~# yum makecache CentOS-8.5.2111 - Base - mirrors.aliyun.com 2.7 MB/s | 4.6 MB 00:01 CentOS-8.5.2111 - Extras - mirrors.aliyun.com 14 kB/s | 10 kB 00:00 CentOS-8.5.2111 - AppStream - mirrors.aliyun.com 3.6 MB/s | 8.4 MB 00:02 MySQL 5.7 Community Server 183 kB/s | 3.1 MB 00:17 元数据缓存已建立。 |

c.安装mysql-server mysql-libs

|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| root@www \~# dnf -y install mysql-server mysql-libs 上次元数据过期检查:0:13:30 前,执行于 2024年11月23日 星期六 02时46分50秒。 ...... 总下载:43 M 安装大小:213 M 下载软件包: ...... ---------------------------------------------------------------------------------------------------------------------------------------------- 总计 5.4 MB/s | 43 MB 00:07 运行事务检查 事务检查成功。 运行事务测试 事务测试成功。 运行事务 ...... 已安装: ...... 完毕! |

d.查验安装结果

|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| root@www \~# rpm -qa | grep mysql mysql-common-8.0.26-1.module_el8.4.0+915+de215114.x86_64 mysql-libs-8.0.26-1.module_el8.4.0+915+de215114.x86_64 mysql-8.0.26-1.module_el8.4.0+915+de215114.x86_64 mysql-server-8.0.26-1.module_el8.4.0+915+de215114.x86_64 mysql-errmsg-8.0.26-1.module_el8.4.0+915+de215114.x86_64 |

e.启动mysql服务,并初次登录,密码为空

|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| root@www \~# systemctl start mysqld root@www \~# systemctl status mysqld ● mysqld.service - MySQL 8.0 database server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled) Active: active (running) since Sat 2024-11-23 19:42:46 EST; 16s ago Process: 2289 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS) Process: 2164 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS) Process: 2140 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS) Main PID: 2245 (mysqld) Status: "Server is operational" Tasks: 38 (limit: 4329) Memory: 379.9M CGroup: /system.slice/mysqld.service └─2245 /usr/libexec/mysqld --basedir=/usr 11月 23 19:42:40 www systemd1: Starting MySQL 8.0 database server... 11月 23 19:42:40 www mysql-prepare-db-dir2164: Initializing MySQL database 11月 23 19:42:46 www systemd1: Started MySQL 8.0 database server. |

f.首次登录数据库系统

|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| root@www \~# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 8.0.26 Source distribution Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> |

数据库登录成功!

在/var/lib/mysql目录下有以下几个重要目录 ,说明MySQL安装成功。

|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| root@www \~# ll /var/lib/mysql 总用量 188876 -rw-r----- 1 mysql mysql 56 11月 23 19:42 auto.cnf -rw-r----- 1 mysql mysql 156 11月 23 19:42 binlog.000001 -rw-r----- 1 mysql mysql 16 11月 23 19:42 binlog.index -rw------- 1 mysql mysql 1680 11月 23 19:42 ca-key.pem -rw-r--r-- 1 mysql mysql 1112 11月 23 19:42 ca.pem -rw-r--r-- 1 mysql mysql 1112 11月 23 19:42 client-cert.pem -rw------- 1 mysql mysql 1680 11月 23 19:42 client-key.pem -rw-r----- 1 mysql mysql 196608 11月 23 19:44 '#ib_16384_0.dblwr' -rw-r----- 1 mysql mysql 8585216 11月 23 19:42 '#ib_16384_1.dblwr' -rw-r----- 1 mysql mysql 5945 11月 23 19:42 ib_buffer_pool -rw-r----- 1 mysql mysql 12582912 11月 23 19:42 ibdata1 -rw-r----- 1 mysql mysql 50331648 11月 23 19:44 ib_logfile0 -rw-r----- 1 mysql mysql 50331648 11月 23 19:42 ib_logfile1 -rw-r----- 1 mysql mysql 12582912 11月 23 19:42 ibtmp1 drwxr-x--- 2 mysql mysql 187 11月 23 19:42 '#innodb_temp' drwxr-x--- 2 mysql mysql 143 11月 23 19:42 mysql -rw-r----- 1 mysql mysql 25165824 11月 23 19:42 mysql.ibd srwxrwxrwx 1 mysql mysql 0 11月 23 19:42 mysql.sock -rw------- 1 mysql mysql 5 11月 23 19:42 mysql.sock.lock -rw-r--r-- 1 mysql mysql 7 11月 23 19:42 mysql_upgrade_info srwxrwxrwx 1 mysql mysql 0 11月 23 19:42 mysqlx.sock -rw------- 1 mysql mysql 6 11月 23 19:42 mysqlx.sock.lock drwxr-x--- 2 mysql mysql 8192 11月 23 19:42 performance_schema -rw------- 1 mysql mysql 1676 11月 23 19:42 private_key.pem -rw-r--r-- 1 mysql mysql 452 11月 23 19:42 public_key.pem -rw-r--r-- 1 mysql mysql 1112 11月 23 19:42 server-cert.pem -rw------- 1 mysql mysql 1680 11月 23 19:42 server-key.pem drwxr-x--- 2 mysql mysql 28 11月 23 19:42 sys -rw-r----- 1 mysql mysql 16777216 11月 23 19:44 undo_001 -rw-r----- 1 mysql mysql 16777216 11月 23 19:44 undo_002 |

g.重置root账户密码

安装MySQL后,首次登录MySQL Server,必须先重置root账户的密码,才能继续使用MySQL。重置root账户密码的命令如下:

alter user root@'localhost' identified by '新密码';

|--------------------------------------------------------------|
| mysql> alter user root@'localhost' identified by'Wu@123456' |

MySQL的密码设置策略如下:至少8个字符,其中至少包含字母、数字和特殊字符或区分大小写。

h.开启远程登录

|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> update user set host = '%' where user = 'root'; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye |

i.启动httpd(如果没安装,参照前面的实验,自行安装设置)

|----------------------------------------------|
| systemctl start httpd systemctl enable httpd |

Apache目录文件

服务目录: /etc//httpd

主配置文件: /etc/httpd/conf/httpd.conf

默认网站主页存放目录: /var/www/html/

日志文件存放目录: /var/log/httpd/

从配置文件(个人主页): /etc/httpd/conf.d/

j.编写自定义主页文件

修改主配置文件,将默认主页存放目录改为/home/www/,并添加首页文件为myweb.html

(5)安装Apache步骤参考上个实验

服务目录:/etc//httpd

主配置文件:/etc/httpd/conf/httpd.conf

默认网站主页存放目录:/var/www/html/

日志文件存放目录:/var/log/httpd/

从配置文件(个人主页):/etc/httpd/conf.d/

编写自定义首页文件

a.修改主配置文件,将默认主页存放目录改为/home/www/,并添加首页文件为wzzweb.html

新建/home/www/目录

图8- 3

b.修改主页文件wzzweb.html

|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| <!doctype html> <html dir="ltr" lang="zh"> <head> <meta charset="utf-8"> <title>服务器管理与应用测试</title> </head> <body> <p>巫正中的课程</p> <p>1001001</p> <p>张三</p> <p>反向渗透测试</p> </body> </html> |

c.修改httpd.conf配置文件(红色部分就是根据自己的规划,进行修改的部分,其他的不要动)

|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| root@www \~# vi /etc/httpd/conf/httpd.conf # ...... # DocumentRoot "/home/www" # # Relax access to content within /var/www. # <Directory "/home/www"> AllowOverride None # Allow open access: Require all granted </Directory> ...... <IfModule dir_module> DirectoryIndex index.html wzzweb.html </IfModule> ...... |

c.windows客户端查看

图8- 4

重启httpd服务。

(6)安装PHP框架

a.安装PHP框架

|-----------------------------------------------------------------------------------------------------------|
| root@www \~# dnf -y install php 上次元数据过期检查:1:38:37 前,执行于 2024年11月23日 星期六 20时03分51秒。 依赖关系解决。 ...... 完毕! |

b.查看版本

|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| root@www \~# php --version PHP 7.2.24 (cli) (built: Oct 22 2019 08:28:36) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies |

c.yum关联php和MySQL服务

|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| root@www \~# php --version PHP 7.2.24 (cli) (built: Oct 22 2019 08:28:36) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies root@www \~# dnf search php-mysql 上次元数据过期检查:1:42:12 前,执行于 2024年11月23日 星期六 20时03分51秒。 =========名称 匹配:php-mysql =========== php-mysqlnd.x86_64 : A module for PHP applications that use MySQL databases root@www \~# dnf install php-mysqlnd.x86_64 -y 上次元数据过期检查:1:42:52 前,执行于 2024年11月23日 星期六 20时03分51秒。 ...... 已安装: php-mysqlnd-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 php-pdo-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 完毕! |

d.安装常用PHP模块

|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| root@www \~# yum install -y php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath 上次元数据过期检查:1:45:17 前,执行于 2024年11月23日 星期六 20时03分51秒。 软件包 curl-7.61.1-22.el8.x86_64 已安装。 ...... 安装 23 软件包 总下载:5.9 M 安装大小:17 M 下载软件包: (1/23): lm_sensors-libs-3.4.0-23.20180522git70f7e08.el8.x86_64.rpm 92 kB/s | 59 kB 00:00 ...... (23/23): unixODBC-2.3.7-1.el8.x86_64.rpm 1.7 MB/s | 458 kB 00:00 ------------------------------------------------------------------------------------------------------------------------------------------------------- 总计 1.6 MB/s | 5.9 MB 00:03 运行事务检查 事务检查成功。 运行事务测试 事务测试成功。 运行事务 ...... 已安装: gd-2.2.5-7.el8.x86_64 jbigkit-libs-2.1-14.el8.x86_64 ...... 完毕! |

e.重启httpd服务

|------------------------------------------|
| root@www \~# systemctl restart httpd |

f.将PHP信息从WEB端输出

进入主页数据目录

|-----------------------------------------------------------------------------------|
| root@www \~# cd /home/www root@www www# vi info.php <?php phpinfo(); ?> |

保存退出。

(7)测试php页面

做了域名解析的:通过http://域名/info.php 能访问。(注意DNS服务器能正常解析)

图8- 5

未做域名解析,通过ip访问:http://IP地址/info.php

图8- 6

综合实验要求:

  1. 重命名(Apache、MySQL、PHP在同一台服务器)的主机名,与学生姓名全拼一致;(10分)

2.MySQL数据库启动成功及查看数据库当前运行状态图; (10分)

3.初次登录数据库重置root账户密码成功图; (10分)

4.Apache服务的主配置文件中,将域名修改成学生自己的域名、默认主页存放目录改为/home/www/,并添加首页文件为myweb.html 的参数更改截图; (10分)

5.在浏览器中分别通过IP、域名访问首页文件成功图(首页文件包括学生专业、姓名、学号、本课程名称); (10分)

  1. 在浏览器中分别通过域名访问个人主页成功图; (10分)

  2. 在浏览器中分别通过域名访问虚拟目录成功图; (10分)

8.安装PHP成功图及PHP相关模块成功图; (10分)

  1. PHP与Mysql数据库关联成功图; (10分)

  2. 在浏览器中通过IP、域名访问PHP首页文件成功图。 (10分)

相关推荐
且从容.1 小时前
Ubuntu安装flume
linux·ubuntu·flume
承渊政道2 小时前
Linux网络学习【Reactor反应堆模式】
linux·网络·学习·ubuntu·reactor
讯捷蓝达4 小时前
戴尔R720xd服务器卡死在 “Configuring Memory...Done“,换了内存还是卡?问题根本不在内存
运维·服务器
且从容.5 小时前
ubuntu安装flink
linux·ubuntu·flink
数字新视界6 小时前
动环监控信创适配在智能机房管理中的应用价值与未来展望
大数据·服务器·数据库·动环监控系统·动力与环境监控系统
爱和冰阔落6 小时前
【Linux网络】TCP 服务器如何并发处理多个客户端?从 fork、僵尸进程到双重 fork
linux·运维·服务器·网络
程序员沉梦听雨6 小时前
WSL2的安装与使用
linux·wsl
微小的鱼6 小时前
Linux的渲染与显示系统链路
android·java·linux
lisanmengmeng7 小时前
alertmanger 标签 rules 打上分组标签
linux·运维·服务器
Android系统攻城狮7 小时前
Linux FFmpeg深度解析之av_write_frame调用流程与实战(三十三)
linux·运维·服务器·ffmpeg·音视频进阶·ffmpeg音视频