日期:2014-05-16  浏览次数:20724 次

linux下如何把apache作为服务运行?

我自己是加了两句话就可以开机启动的:

chkconfig --add httpd
chkconfig httpd on

前提是用yum 安装 apache

?

其实在源码里已经有启动的脚本,我们要修改下即可,把Apache加入系统SysV服务中来。
在源码httpd-2.x.x/build/rpm中存在httpd.init
cp httpd-2.x.x/build/rpm/httpd.init /etc/init.d/httpd


  长久以来linux下apache的启动是在/etc/rc.d/rc.local文件中添加/opt/www/bin/apachectl start来实现开机启动。

  现在用如下方法可以把apache放入服务中运行。

第一步
cp bin/apachectl /etc/init.d/httpd

第二步
vi /etc/init.d/httpd
加入:
# Startup script for the Apache Web Server
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve
# HTML files and CGI.
# processname: httpd
# pidfile: /opt/www/log/httpd.pid
# config: /opt/www/conf/httpd.conf

第三步
chmod 755 /etc/init.d/httpd
chkconfig --add httpd
chkconfig httpd on

然后就可以使用如下指命启动、停止、重启apache了
service httpd start
service httpd stop
service httpd restart