centos7搭建Apache服务


实验要求:首页文件存放于/var/www/apache,首页文件名称:apache.html,端口号:66;这个实验是很基础的

配置网络


[root@localhost ~]# nmcli connection  modify "ens33" ipv4.method manual ipv4.addresses "192.168.131.66/24" ipv4.gateway "192.168.131.2" ipv4.dns "114.114.114.114" connection.autoconnect yes
[root@localhost ~]# nmcli con down  ens33 
Connection 'ens33' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)
[root@localhost ~]# nmcli  con up ens33 
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
[root@localhost ~]# 

##测试网络
[root@localhost ~]# ping www.baidu.com
PING www.a.shifen.com (36.152.44.96) 56(84) bytes of data.
64 bytes from 36.152.44.96 (36.152.44.96): icmp_seq=1 ttl=128 time=35.6 ms

关闭SELinux

[root@localhost ~]# vim /etc/selinux/config
SELINUX=disabled

[root@localhost ~]# setenforce 0

配置本地yum

##挂载镜像文件
[root@localhost ~]# mount /dev/sr0 /mnt/
mount: /dev/sr0 is write-protected, mounting read-only

##把原先yum的repo文件另存一个目录
[root@localhost ~]# mkdir  /tmp/repo
[root@localhost ~]# mv /etc/yum.repos.d/CentOS-* /tmp/repo/

##创建本地yum源
[root@localhost ~]# vim /etc/yum.repos.d/apache.repo
[centos]
name=apache
baseurl=file:///mnt
enabled=1
gpgcheck=0

##清除缓存并查看是否成功配置
[root@localhost ~]# yum clean all;yum repolist 
Loaded plugins: fastestmirror, langpacks
Cleaning repos: centos
Cleaning up list of fastest mirrors
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
centos                                                                                                         | 3.6 kB  00:00:00     
(1/2): centos/group_gz                                                                                         | 165 kB  00:00:00     
(2/2): centos/primary_db                                                                                       | 3.2 MB  00:00:00     
repo id                                                         repo name                                                       status
centos                                                          apache                                                          4,067
repolist: 4,067
[root@localhost ~]# 


安装服务

[root@localhost Packages]# yum install -y httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-90.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.6-90.el7.centos for package: httpd-2.4.6-90.el7.centos.x86_64

##
[root@localhost Packages]# rpm -qa httpd
httpd-2.4.6-90.el7.centos.x86_64
[root@localhost Packages]# 


放行Apache端口号及关闭防火墙

##永久放行端口
[root@localhost Packages]# firewall-cmd --permanent --add-service="http"
success

##重新加载
[root@localhost Packages]# firewall-cmd --reload 
success

##关闭防火墙及开机不开启
[root@localhost Packages]# systemctl stop firewalld.service 
[root@localhost Packages]# systemctl disable firewalld.service 

修改配置文件

##创建存放首页文件的目录
[root@localhost conf]# mkdir  /var/www/apache

##先复制一份备用以防万一
[root@localhost Packages]# cd /etc/httpd/conf/
[root@localhost conf]# cp httpd.conf httpd.conf.bak


##进入配置文件,更改存放首页文件的目录、首页文件名称及端口号
[root@localhost conf]# vim httpd.conf
#DocumentRoot "/var/www/html"
DocumentRoot "/var/www/apache"

#DirectoryIndex index.html
DirectoryIndex apache.html

#Listen 80
Listen 66

##自定义一个网页,有能力的小伙伴可以自己使网页更精彩
[root@localhost conf]# cd/var/www/apache/
[root@localhost apache]# vim apache.html
Hello ,This is a test!



启动服务并查看

##添加临时解析
[root@localhost www]# echo '192.168.131.66 www.apache.com' >> /etc/hosts

##重启服务
[root@localhost apache]# systemctl restart httpd.service

查看
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值