发表于 2018-11-18 10:32:45

CentOS 安装 apache

  apache在centos7中是Apache HTTP server。如下对httpd的解释就是Apache HTTP Server。所以想安装apache其实是要安装httpd。
  

  # yum install httpd#安装
  

  # 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.
  #
  

  

  # service httpd start    #启动服务
  Redirecting to /bin/systemctl starthttpd.service
  #
  

  

  # 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
  #
  

  到这里时,在本机是可以访问 web 的,但其他局域网电脑不可以访问 web,此原因是防火墙导致:
  # curl 127.0.0.1
  

  开启防火墙:centos的防火墙改成了firewall,不再叫iptables,开放端口的方法如下
  # firewall-cmd --zone=public --add-port=80/tcp --permanent
  success
  #
  

  命令含义:
  --zone #作用域
  --add-port=80/tcp#添加端口,格式为:端口/通讯协议
  --permanent   #永久生效,没有此参数重启后失效
  

  重启防火墙命令:
  # systemctl restart firewalld.service
  # systemctl stop firewalld.service
  # systemctl start firewalld.service
  

  到这里,局域网电脑就可以访问 web了
  




页: [1]
查看完整版本: CentOS 安装 apache