apache在centos7中是Apache HTTP server。如下对httpd的解释就是Apache HTTP Server。所以想安装apache其实是要安装httpd。
[root@localhost ~]# yum install httpd #安装
[root@localhost ~]# chkconfig httpd on#设置开机启动
Note: Forwarding request to 'systemctl enable httpd.service'.
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@localhost ~]#
[root@localhost ~]# service httpd start#启动服务
Redirecting to /bin/systemctl start httpd.service
[root@localhost ~]#
[root@localhost ~]# netstat -ntlp#查看 80 端口是否启动
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 958/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1456/master
tcp6 0 0 :::80 :::* LISTEN 2363/httpd
tcp6 0 0 :::22 :::* LISTEN 958/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1456/master
[root@localhost ~]#
到这里时,在本机是可以访问 web 的,但其他局域网电脑不可以访问 web,此原因是防火墙导致:
[root@localhost ~]# curl 127.0.0.1
开启防火墙:centos的防火墙改成了firewall,不再叫iptables,开放端口的方法如下
[root@localhost ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@localhost ~]#
命令含义:
--zone #作用域
--add-port=80/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效
重启防火墙命令:
[root@localhost ~]# systemctl restart firewalld.service
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# systemctl start firewalld.service
到这里,局域网电脑就可以访问 web了
原文链接:https://www.f2er.com/centos/376184.html