Apache服务器简介
Apache可以运行在广泛使用的计算机平台上,其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一
环境配置
yum源配置
挂载光盘 mount /dev/sr0 /media/
配置yum源文件
[AppStream]
name = AppStream
baseurl=file:///media/AppStream
gpgcheck=0
enable=1
[BaseOS]
name = BaseOS
baseurl=file:///media/BaseOS
gpgcheck=0
enable=1
安装Apache
安装Apache服务 yum -y install httpd
安装php yum -y install php php*
防火墙配置
关闭防火墙命令 systemctl stop firewalld.service
防火墙临时放行 http firewall-cmd --add-service=http
防火墙永久放行 http firewall-cmd --add-service=http --permanent
ip地址配置
nmcli配置ip地址 nmcli connection modify ens160 ipv4.addresses 10.10.100.1/24
nmcli配置dns nmcli connection modify ens160 ipv4.dns 10.10.100.1
激活网卡 nmcli connection up ens160
#ens160是网卡名称,每个系统版本都不一样,视情况而定
Apache配置
开机自启动Apache systemctl enable httpd重启Apache systemctl restart httpd查看Apache状态 systemctl status httpd
写一个简单的php文件
新建一个目录 mkdir /data/www -p //-p检测有没有这个目录,没有自动创建
在/data/www 目录下新建index.php //后缀名为.php即可
php文件内容 <?php echo "hello this is a web" ;?> //echo后面内容可以自定
新建一个虚拟站点
vim /etc/conf.d/www.com.conf #以.conf结尾即可
<VirtualHost *:80>
Servername 10.10.100.1 //网站域名DocumentRoot /data/www //目录
DirectoryIndex index.php //文件
</VirtualHost><Directory "/data/www">
require all granted //允许所有访问请求
</Directory>
使用curl命令测试
IP地址访问
出现下图这种情况是selinux没有关闭setenforce 0可临时关闭selinux

查看selinux状态 getenforce #下图是关闭状态

再次测试 curl http://10.10.100.1 #成功显示刚才的php文件

windows打开浏览器搜索http://10.10.100.1 #地址根据自己配置的来

域名访问
dns主文件配置zone "example.com" IN {
type master;
file "example.com.zone";
};
zone "100.10.10.in-addr.arpa" IN {
type master;
file "10.10.100.arpa";
};


vim /etc/conf.d/www.com.conf #以.conf结尾即可
<VirtualHost *:80>
Servername www.example.com //网站域名DocumentRoot /data/www //目录
DirectoryIndex index.php //文件
</VirtualHost><Directory "/data/www">
require all granted //允许所有访问请求
</Directory>

curl命令测试 curl http://www.example.com

windows测试 浏览器搜索http://www.example.com
