实验环境
用的是阿里云上面的服务器
[root@iZ1i4qd6oynml0Z ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[root@iZ1i4qd6oynml0Z ~]# uname -a
Linux iZ1i4qd6oynml0Z 3.10.0-514.26.2.el7.x86_64 #1 SMP Tue Jul 4 15:04:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
-
安装Apache
[root@iZ1i4qd6oynml0Z ~]# yum install httpd
-
设置httpd服务开机启动
[root@iZ1i4qd6oynml0Z ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
-
启动Apache
[root@iZ1i4qd6oynml0Z ~]# systemctl start httpd
-
查看Apache的状态
[root@iZ1i4qd6oynml0Z ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2020-04-12 09:10:39 CST; 44s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 2580 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─2580 /usr/sbin/httpd -DFOREGROUND
├─2581 /usr/sbin/httpd -DFOREGROUND
├─2582 /usr/sbin/httpd -DFOREGROUND
├─2583 /usr/sbin/httpd -DFOREGROUND
├─2584 /usr/sbin/httpd -DFOREGROUND
└─2585 /usr/sbin/httpd -DFOREGROUND
Apr 12 09:10:39 iZ1i4qd6oynml0Z systemd[1]: Starting The Apache HTTP Server...
Apr 12 09:10:39 iZ1i4qd6oynml0Z httpd[2580]: AH00558: httpd: Could not reliably determine the server\'s fully qualifie...essage
Apr 12 09:10:39 iZ1i4qd6oynml0Z systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
-
确认80端口的状态
[root@iZ1i4qd6oynml0Z ~]# netstat -tulp
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:http 0.0.0.0:* LISTEN 2580/httpd
tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN 2185/sshd
tcp 0 0 localhost:32000 0.0.0.0:* LISTEN 1161/java
udp 0 0 0.0.0.0:bootpc 0.0.0.0:* 683/dhclient
udp 0 0 iZ1i4qd6oynml0Z:ntp 0.0.0.0:* 771/ntpd
udp 0 0 localhost:ntp 0.0.0.0:* 771/ntpd
udp 0 0 0.0.0.0:ntp 0.0.0.0:* 771/ntpd
udp 0 0 0.0.0.0:56212 0.0.0.0:* 683/dhclient
udp6 0 0 [::]:ntp [::]:* 771/ntpd
udp6 0 0 [::]:63075 [::]:* 683/dhclient
-
查看Apache的版本
[root@iZ1i4qd6oynml0Z ~]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Aug 8 2019 11:41:18
-
验证安装
用浏览器打开服务器的IP地址,将看到默认的Apache欢迎页面表示成功
-
Apache命令
停止Apache服务
systemctl stop httpd
启动Apache服务
systemctl start httpd
重启Apache服务
systemctl restart httpd
禁用Apache开机自启动
systemctl disable httpd
Apache开机自启动
systemctl enable httpd
更改配置后重新加载Apache服务
systemctl reload httpd
Apache的主配置文件:/etc/httpd/conf/httpd.conf
安装完后就可以到Apache的默认目录/var/www/html 添加一个简单的index.html
<!DOCTYPE html>
<head>
<title>test</title>
</head>
<body>
<p>Hello World!</p>
</body>
</html>
再次在浏览器输入ip地址就会显示以下界面