apache在centos7中是Apache HTTP server。如下对httpd的解释就是Apache HTTP Server。所以想安装apache其实是要安装httpd。
[[email protected] ~]# yum install httpd #安装
[[email protected] ~]# 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.
[[email protected] ~]#
[[email protected] ~]# service httpd start #启动服务
Redirecting to /bin/systemctl start httpd.service
[[email protected] ~]#
[[email protected] ~]# 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
[[email protected] ~]#
到这里时,在本机是可以访问 web 的,但其他局域网电脑不可以访问 web,此原因是防火墙导致:
[[email protected] ~]# curl 127.0.0.1
开启防火墙:centos的防火墙改成了firewall,不再叫iptables,开放端口的方法如下
[[email protected] ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[[email protected] ~]#
命令含义:
--zone #作用域
--add-port=80/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效
重启防火墙命令:
[[email protected] ~]# systemctl restart firewalld.service
[[email protected] ~]# systemctl stop firewalld.service
[[email protected] ~]# systemctl start firewalld.service
到这里,局域网电脑就可以访问 web了