LAMP实验
LAMP
关闭防火墙和SElinux
systemctl stop firewalld && setenforce 0
确保CentOS系统已经安装了Apache、MySQL和PHP。可以使用以下命令检查它们是否已安装:
yum list installed httpd mariadb-server php php-mysqlnd
如果它们没有安装,可以使用以下命令安装它们:
yum install httpd mariadb-server php php-mysqlnd -y
Apache
httpd -t:语法检查
httpd -v:查看版本
httpd -m :查看模块
全局配置:
ServerName:对应域名
DocumentRoot:对应网站根目录
DirectoryIndex:网站默认首页
网站根目录
mkdir /var/qziedu
mkdir /var/jwgl
echo "qziedu" > /var/qziedu/学号.html
echo "jwgl" > /var/jwgl/学号.html
mkdir /var/学号
echo "test" > /var/学号/test.txt
虚拟主机
qziedu
在 /etc/httpd/conf.d 下创建一个 qziedu.cn.conf 的文件,要确保文件具有可读的权限,目录具有可读可执行的权限。
vim /etc/httpd/conf.d/qziedu.cn.conf
chmod 744 /etc/httpd/conf.d/qziedu.cn.conf
向其中写入配置:
<VirtualHost *:80>
ServerAdmin webmaster@qziedu.cn
ServerName www.qziedu.cn
DocumentRoot /var/qziedu
DirectoryIndex 学号.html
Alias /学号 /var/学号 #虚拟目录映射,访问 url/学号 对应的是/var/学号
<Directory /var/qziedu> #目录权限设置
Options Indexes FollowSymLinks #可以目录访问
AllowOverride None
Require all granted
</Directory>
<Directory /var/学号>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
学号替换可以使用%s/学号/2103180900/g
jwgl
编辑配置文件
vim /etc/httpd/conf.d/jwgl.cn.conf
<VirtualHost *:80>
ServerAdmin webmaster@qziedu.cn
ServerName www.jwgl.cn
DocumentRoot /var/jwgl
DirectoryIndex 学号.html
<Directory /var/jwgl>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
host
配置以下host文件就可以访问了。
phpmyadmin
安装EPEL存储库,因为phpMyAdmin包通常在EPEL存储库中:
yum install epel-release -y
安装phpMyAdmin包:
yum install phpmyadmin -y
编辑配置文件:
vim /etc/httpd/conf.d/phpMyAdmin.conf
找出并注释掉带有"Require ip XXXX"字样的代码行。会有四处这样的代码行,用"Require all granted"取而代之。
vim快捷:
%s/Require ip 127.0.0.1/Require all granted/g
%s/Require ip ::1/#Require ip ::1/g
我这里下载是没有带DirectoryIndex index.php这一行的,要自己添加进去才能访问。
修改完如下:
Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin
<Directory /usr/share/phpMyAdmin/>
AddDefaultCharset UTF-8
DirectoryIndex index.php
<IfModule mod_authz_core.c>
# Apache 2.4
<RequireAny>
Require all granted
</RequireAny>
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
</Directory>
<Directory /usr/share/phpMyAdmin/setup/>
<IfModule mod_authz_core.c>
# Apache 2.4
<RequireAny>
Require all granted
</RequireAny>
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
</Directory>
<Directory /usr/share/phpMyAdmin/libraries/>
<IfModule mod_authz_core.c>
# Apache 2.4
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from None
</IfModule>
</Directory>
<Directory /usr/share/phpMyAdmin/setup/lib/>
<IfModule mod_authz_core.c>
# Apache 2.4
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from None
</IfModule>
</Directory>
<Directory /usr/share/phpMyAdmin/setup/frames/>
<IfModule mod_authz_core.c>
# Apache 2.4
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from None
</IfModule>
</Directory>
重启服务 httpd 服务就完成了。

浙公网安备 33010602011771号