# cd /etc/init.d
# vi apache2
加上以下脚本
#!/bin/sh
# description: Apache auto start-stop script.
# chkconfig: - 85 15
APACHE_HOME=/usr/local/apache2
APACHE_OWNER=root
if [ ! -f "$APACHE_HOME/bin/apachectl" ]
then
echo "Apache startup: cannot start"
exit
fi
case "$1" in
'start')
su - $APACHE_OWNER -c "$APACHE_HOME/bin/apachectl start"
;;
'stop')
su - $APACHE_OWNER -c "$APACHE_HOME/bin/apachectl stop"
;;
'restart')
su - $APACHE_OWNER -c "$APACHE_HOME/bin/apachectl restart"
;;
esac
# chmod 755 apache
# chkconfig --add apache
# chkconfig --level 345 apache2 on
Ok,测试Apache
# service apache2 start
# service apache2 stop
# service apache2 restart
同时reboot OS试一下apache是否开机自动运行了。