在Linux啟動(dòng)時(shí)讓Apache也自動(dòng)啟動(dòng)

字號(hào):

現(xiàn)對(duì)如何讓Apache隨Linux啟動(dòng)而啟動(dòng)的方法做個(gè)總結(jié),總結(jié)如下:
    1 cd /etc/init.d
    2 vi apache2
    3 粘貼以下代碼
    #!/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
    4 chmod +x apache2
    5 chkconfig --add apache2
    6 chkconfig -level 345 apache2 on
    7 service apache2 start 啟動(dòng)apache server
    8 重新啟動(dòng)Linux,并驗(yàn)證Apache是否隨Linux啟動(dòng)
    如果上述操作無(wú)誤,結(jié)果應(yīng)該是ok的!