1、配置yum源,前面已经讲过,可以查看前一篇内容
2、安装Apache服务:yum install httpd.x86_64 httpd-manual.noarch -y
3、重启服务 systemctl restart httpd
4、搭建基于域名的虚拟主机:
rpm -qc httpd //查看与apache相关的所有的配置文件
apache的主配置文件:/etc/httpd/conf/httpd.conf
主配置目录:ServerRoot "/etc/httpd"
IncludeOptional conf.d/*.conf
5、建立虚拟主机配置文件,vim /etc/httpd/conf.d/vhost.conf
添加以下内容:<virtualHost *:80>
ServerAdmin root@www.XXXXXX.com //自定义
DocumentRoot /var/www/html
ServerName www.XXXXXX.com //自定义
</VirtualHost>
6、做dns本地解析,vim /etc/hosts
在该文件最后一行加上域名对应的解析,例如192.168.X.X www.XXXXXX.com,ip为服务器ip。
7、在/var/www/html目录中添加所想显示的文件,如:vim /var/www/html/hello.txt
8、放行防火墙的http服务,firewall-config打开防火墙图形化界面,勾选http。
或命令:firewall-cmd --add-service=http --permanent,再重启firewall-cmd --reload
9、浏览器访问www.XXXXXX.com/hello.txt,成功显示即可