【LAMP 基于 Red Hat Linux 7】

本指南搭建基于 rhel 7.5 Apache MariaDB PHP ,并创建自定义数据测试系统。
1. Linux 版本说明
Red Hat Enterprise Linux Server release 7.5 (Maipo)
使用对应的 Linux 系统 iso 文件中的包完成 Apache MariaDB PHP 的安装。
2. 环境准备
2.1. 关闭防火墙
# systemctl stop firewalld
2.2. 设置 selinux 为宽容模式
# setenforce 0
2.3. 配置本地光盘为 yum
2.3.1. 连接 iso 文件到 CD/DVD 设备

2.3.2. 挂载 CD/DVD 设备

# mount /dev/cdrom /media/cdrom

 2.3.3. 生成 dvd.repo 文件

3. 安装 Apache
1. 使用 yum 命令安装 httpd 软件包
# yum -y install httpd
2. 启动 httpd 服务,并配置开机启动
# systemctl start httpd 
# systemctl enable httpd
3. 关闭防火墙,并配置开机不启动
# systemctl stop firewalld 
# systemctl disable firewalld
4. 查看 httpd 服务运行状态和链接状态
# systemctl status httpd 
# ss -antup | grep 80
5. 测试 httpd 服务
# 在 /var/www/html 目录下写入主页文件 
[root@localhost ~]# echo "Hello World" > /var/www/html/index.html
 [root@localhost ~]# curl localhost Hello World
4. 安装 MariaDB 服务器和客户端
4.1. 通过 yum 命令安装 MariaDB 服务器和客户端软件
# yum -y install mariadb-server mariadb
4.2. 启动 mariadb 服务
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# systemctl status mariadb 
● mariadb.service - MariaDB database server 
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled) Active: active (running) since Sun 2021-11-28 16:29:14 PST; 6h ago Main PID: 1408 (mysqld_safe) 
CGroup: /system.slice/mariadb.service ├─1408 /bin/sh /usr/bin/mysqld_safe --basedir=/usr └─1678 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql -- 
plugin-dir=/usr/lib64/mysql/plugin --log-error... Nov 28 16:29:09 localhost.localdomain systemd[1]: Starting MariaDB database server... Nov 28 16:29:10 localhost.localdomain mariadb-prepare-db-dir[1295]: Database MariaDB is probably initialized in /var/lib/m...one. Nov 28 16:29:10 localhost.localdomain mysqld_safe[1408]: 211128 16:29:10 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'. Nov 28 16:29:10 localhost.localdomain mysqld_safe[1408]: 211128 16:29:10 mysqld_safe Starting mysqld daemon with database...mysql Nov 28 16:29:14 localhost.localdomain systemd[1]: Started MariaDB database server. Hint: Some lines were ellipsized, use -l to show in full.
4.3. 配置 mariadb 服务开机启动
# systemctl enable mariadb
4.4. 初始化数据库安全
通过 mysql_secure_installation 安全脚本,可以快速配置数据库安全:为 root 用户设置密码;禁止
root 用户远程登录;删除匿名账号;删除 test 数据库;
[root@localhost ~]# mysql_secure_installation 
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! 
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. 
Enter current password for root (enter for none): # 输入 root 当前密码,没有密码,直 接按回车 

OK, successfully used password, moving on... 
Setting the root password ensures that nobody can log into the MariaDB 
root user without the proper authorisation. 
Set root password? [Y/n] y # 是否设置 root 密码 --> 选择Y,密码设置为123456 
New password: 
Re-enter new password:
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 # 是否删除匿名账号 --> 输入 n ... Success! 
Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. 
Disallow root login remotely? [Y/n] y # 是否允许 root 远程登录 --> 输入 n ... Success!
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.
 Remove test database and access to it? [Y/n] y # 是否删除 test 数据库,及其访问权限 --> 输入 n - Dropping test database... ... Success! - 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 # 是否立即加载权限表 --> 输入 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!
5. 安装 php
使用 yum 命令安装 php php-mysql php-mysql 可以让 PHP 连接数据库。
# yum install -y php php-mysql
6. 重启 httpd 服务
# systemctl restart httpd
7. 创建 php 信息页面测试
1. /var/www/html 目录下创建 info.php 文件,内容如下:
<?php 
phpinfo();
 ?>
2. 查看 Linux 虚拟机 ip 地址
# ip a
2. Windows 宿主机,使用浏览器访问 info.php 页面
地址示例: http://192.168.206.128/info.php
8. 使用 php 连接数据库
8.1. 通过文件导入数据库测试数据
#mysql -u root -p123456 < student.sql
8.2. php 脚本文件上传到 /var/www/html/ 目录
使用 MobaXterm student_info.php 文件上传到 /var/www/html 目录中:

8.3. 通过 Windows 浏览器访问 student_info.php 页面

 

 

 

 

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Goat_1 3

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值