之前搭完LAMP环境后,就将虚拟机给关了;
今天重新打开虚拟机后,发现访问不了网站了。
记录一下解决步骤
- 先查看各个服务有没有打开
ps -ef | grep -E 'php|mysql|httpd' | grep -v grep
结果root 977 1 0 21:27 ? 00:00:00 php-fpm: master process (/etc/php-fpm.conf) root 991 1 0 21:27 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND mysql 1073 1 0 21:27 ? 00:00:03 /usr/libexec/mysqld --basedir=/usr apache 1227 991 0 21:27 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 1228 991 0 21:27 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 1229 991 0 21:27 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 1230 991 0 21:27 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND apache 1751 977 0 21:27 ? 00:00:00 php-fpm: pool www apache 1752 977 0 21:27 ? 00:00:00 php-fpm: pool www apache 1753 977 0 21:27 ? 00:00:00 php-fpm: pool www apache 1754 977 0 21:27 ? 00:00:00 php-fpm: pool www apache 1755 977 0 21:27 ? 00:00:00 php-fpm: pool www apache 7150 991 0 21:36 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
可以看到PHP,MYSQL和httpd都是开启的;
- 再看下httpd服务监听的是哪个端口
netstat -ntulp | grep httpd
tcp6 0 0 :::80 :::* LISTEN 991/httpd
端口号是80, 类型是tcp - 在本地看本机web服务是否有效运行
telnet 127.0.0.1 80
Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'.
可以看到本机是能正常访问的。
- 再查看防火墙设置
- 看下防火墙的状态
systemctl status firewalld
firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2023-11-08 21:27:25 CST; 22min ago
防火墙是开启的;
- 看下防火墙有没有开放80端口
firewall-cmd --query-port=80/tcp
结果是no
- 所以这里设置防火墙放开80端口:
firewall-cmd --add-port=80/tcp --permanent
【--permanent表示永久开放,否则重启后就失效了】 - 重启防火墙
systemctl restart firewalld.service
- 再看防火墙有没有打开tcp 80端口
firewall-cmd --query-port=80/tcp
显示结果是yes
,表示开放成功 - 再访问下网站看看
解决了
- 看下防火墙的状态
留言