Linux/CentOS8配置web服务器,完成虚拟目录,静态IP,端口号,动态LAMP配置

点击这里:阿里镜像下载
选这个
报错一:启动虚拟机时显示:ide1:0,因为主机没有相应的设备?
解决:在这里插入图片描述
两个勾勾勾上
使用ISO映像文件
在这里插入图片描述
可去这里:https://blog.csdn.net/play_chess_ITmanito/article/details/83862568

注意:gjz为本人姓名缩写,也是本机用户

su root
mkdir /mnt/cdrom
mount /dev/cdrom /mnt/cdrom
vim /etc/yum.repos.d/base.repo
[BaseOS]
name=BaseOS
baseurl=file:///mnt/cdrom/BaseOS
enabled=1
gpgcheck=0
[AppStream]
name=AppStream
baseurl=file:///mnt/cdrom/AppStream
enabled=1
gpgcheck=0
dnf install httpd -y      //或者使用  yum install httpd -y

报错二:yum 源配置
问题如下

yum update

CentOS-8 - Base 29 B/s | 153 B 00:05
Errors during downloading metadata for repository ‘BaseOS’:

  • Status code: 404 for https://mirrors.tuna.tsinghua.edu.cn/centos/8/BaseOS/x86_64/os/repodata/repomd.xml (IP: 101.6.15.130)
    Error: Failed to download metadata for repo ‘BaseOS’: Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried

可去:https://blog.csdn.net/qq_38883889/article/details/123062993

systemctl start httpd
systemctl enable httpd
systemctl stop firewalld
setenforce 0
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
echo "this is 192.168.112.133'web" > /var/www/html/index.html

//保持关闭防火墙和SELinux
即:
systemctl stop firewalld
setenforce 0

三、

chmod -R 705 /home/gjz
mkdir /home/gjz/public_html
echo "this is gjz's web" > /home/gjz/public_html/index.html
vim /etc/httpd/conf.d/userdir.conf

找到下面两个,更改后如下

#UserDir disabled
 UserDir public_html

重启

systemctl restart httpd

浏览器 http://ip/~gjz

firewall-cmd --permanent --add-service=http
firewall-cmd --reload

四、配置虚拟目录

mkdir /gjz
echo "virtual directory" > /gjz/index.html
chmod -R 705 /gjz

vim /etc/httpd/conf/httpd.conf
Alias /test "/gjz"
<Directory "/gjz">
	AllowOverride None
	Require all granted
</Directory>
systemctl restart httpd

浏览器 ip/test

五、

1、配置IP

cd /etc/sysconfig/network-scripts
ls

vim 空格+Tab进去配置
注意:IPADDR=192.168.112.133 为centosIP
IPADDR1 大概在IP范围内即可,我直接133+1
ip address 查看ip

GATEWAY=192.168.112.0 为网关,值写这个子网IP好像也行
在这里插入图片描述
在这里插入图片描述

BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.112.133 
IPADDR1=192.168.112.134
NETMASK=255.255.255.0
GATEWAY=192.168.112.0
DNS1=114.114.114.114
DNS2=8.8.8.8
reboot 
su root
systemctl start httpd
systemctl stop firewalld
setenforce 0
mkdir /var/www/example
echo "This is 192.168.112.134'web" > /var/www/example/index.html
vim /etc/httpd/conf/httpd.conf
<VirtualHost 192.168.112.134>
	DocumentRoot "/var/www/example"
	ServerName server.example.com
	<Directory "/var/www/example">
	AllowOverride None
	Require all granted
	</Directory>
</VirtualHost>
systemctl restart httpd

浏览器打开 192.168.112.134

2、配置端口8000和8080

mkdir /var/www/{8000,8080}
echo "this is 8000 prot'web" > /var/www/8000/index.html
echo "this is 8080 prot'web" > /var/www/8080/index.html
systemctl stop firewalld
setenforce 0
vim /etc/httpd/conf/httpd.conf

#45行左右

Listen 8000
Listen 8080

#175行左右


<VirtualHost 192.168.112.133:8000>
	DocumentRoot "/var/www/8000"
	ServerName server.example.com
	<Directory "/var/www/8000">
	AllowOverride None
	Require all granted
	</Directory>
</VirtualHost>

<VirtualHost 192.168.112.133:8080>
	DocumentRoot "/var/www/8080"
	ServerName server.example.com
	<Directory "/var/www/8080">
	AllowOverride None
	Require all granted
	</Directory>
</VirtualHost>

浏览器打开192.168.112.133:8000
浏览器打开192.168.112.133:8080

systemctl restart httpd

扩展LAMP

yum install -y mariadb-server
systemctl start mariadb
systemctl enable mariadb

下面这个可能报错,但对本次实验影响不太大,可将命令拆分着写,最后输密码

mysqladmin -uroot password '123'
yum module list php

我是下载的 php:7.4,下载较为新的即可

yum module enable php:7.4
yum install -y php php-mysqlnd
echo "<?php phpinfo();?>" > /var/www/html/index.php
setenforce 0
systemctl stop firewalld
systemctl restart httpd

浏览器 ip/index.php

报错三:[php] <?php phpinfo(); ?>无显示
可去:[php] <?php phpinfo(); ?>只显示源代码 / 无显示

参考:
https://blog.csdn.net/weixin_43182313/article/details/110122710
https://blog.csdn.net/play_chess_ITmanito/article/details/83862568
https://blog.csdn.net/qq_38883889/article/details/123062993

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值