在 CentOS 上设置 Apache(httpd)开机自启,取决于你使用的 CentOS 版本(6 或 7/8/Stream)。下面分别说明。
sudo yum install httpd -y
# 或 CentOS 8/Stream
sudo dnf install httpd -y
sudo systemctl enable httpd
sudo systemctl start httpd
sudo systemctl status httpd
sudo systemctl stop httpd # 停止
sudo systemctl restart httpd # 重启
sudo systemctl reload httpd # 重载配置
sudo chkconfig httpd on
sudo service httpd start
sudo service httpd status
systemctl is-enabled httpd
输出应为:
enabled
chkconfig --list httpd
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT
sudo service iptables save
查看日志:
sudo journalctl -xe
# 或
sudo tail -f /var/log/httpd/error_log
sudo netstat -tulnp | grep :80
如果你愿意,可以告诉我:
cat /etc/centos-release)我可以给你更精确的配置方案。