linux中,通过yum安装Apache 会默认把服务添加到系统服务中,通过chkconfig设置开机启动就可以实现Apache开机自启。
编译的Apache,要先添加到系统中,或者添加到系统服务中心。
方式1:
操作步骤:
1、将Apache启动命令复制到系统服务启动目录下
# cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
2、加入服务
# chkconfig --add httpd
注意:如果chkconfig --add httpd 出现service httpd does not support chkconfig
错误. 需要在/etc/init.d/httpd文件中加入配置:
vim /etc/init.d/httpd #chkconfig:345 85 15 #description: Start and stops the Apache HTTP Server.
3、 设置开机自启
# chkconfig httpd on
4、查看服务
# chkconfig --list
方式2:
将Apache开机启动脚本写入/etc/rc.d/rc.local
# vim /etc/rc.d/rc.local /usr/local/httpd/bin/apachectl start
# Apache常用命令
1. 启动、终止、重启
systemctl start httpd.service #启动
systemctl stop httpd.service #停止
systemctl restart httpd.service #重启
2. 设置开机启动/关闭
systemctl enable httpd.service #开机启动
systemctl disable httpd.service #开机不启动
systemctl list-unit-files | grep httpd # 检查Apache是否已经安装了开机自动启动
systemctl status httpd.service #检查状态