自行編譯安裝 Apache 後,執行 service httpd restart 提示「httpd 未被識別的服務」。臨時啟動可用:
/usr/local/apache2/bin/apachectl start
若要使用 service 管理,需建立 /etc/init.d/httpd 啟動腳本:
touch /etc/init.d/httpd
chmod 755 /etc/init.d/httpd
vi /etc/init.d/httpd
腳本內容(請依實際安裝路徑調整 daemon 路徑):
#!/bin/bash
# chkconfig: 2345 85 85
# description: httpd is a web server
# processname: httpd
. /etc/init.d/functions
RETVAL=0
start() {
echo -n "Starting httpd service: "
daemon /usr/local/apache2/bin/apachectl start
RETVAL=$?
echo
}
stop() {
echo -n "Shutting down httpd service: "
daemon /usr/local/apache2/bin/apachectl stop
RETVAL=$?
echo
}
case "$1" in
start) start ;;
stop) stop ;;
restart|reload) stop; start ;;
*) echo "Usage: $0 {start|stop|restart}"; exit 1 ;;
esac
exit $RETVAL
建立後執行 chkconfig --add httpd 並 chkconfig httpd on 設定開機自啟,即可使用 service httpd restart 管理。