Apache 1.3 の起動

インストールした Apache を起動して動作の確認を行います。
また Apache の自動起動スクリプトを作成して OS 起動時に自動的に Apache を起動するように設定します。

Apache の起動と終了

Apache は apachectl 制御スクリプトを使っての起動します。

# /usr/local/httpd/bin/apachectl start

ウェブブラウザを使って http://192.168.0.2/ のようにサーバーの IP アドレスを入力し以下のように表示されることを確認します。

apache の起動

Apache を停止する場合も apachectl 制御スクリプトを使います。

# /usr/local/httpd/bin/apachectl stop

Apache の自動起動 スクリプト

Apache の自動起動スクリプトを使うことで、サーバーマシンが起動するときに自動的に Apache を起動させることができます。
Apache の自動起動スクリプト /etc/rc.d/init.d/httpd ファイルを以下のように作成します。

# vi /etc/rc.d/init.d/httpd
/etc/rc.d/init.d/httpd
#!/bin/bash
#
# Startup script for the Apache Web Server
#
# chkconfig: 2345 85 15
# description: Apache is a World Wide Web server.  It is used to serve \
#              HTML files and CGI.
# processname: httpd
# pidfile: /var/run/httpd.pid
# config: /usr/local/httpd/conf/httpd.conf

# Source function library.
. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi

# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=”"

# Set HTTPD=/usr/local/httpd/bin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based “worker” MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.

# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/httpd/bin/apachectl
httpd=${HTTPD-/usr/local/httpd/bin/httpd}
prog=httpd
RETVAL=0

# The semantics of these two functions differ from the way apachectl does
# things — attempting to start while running is a failure, and shutdown
# when not running is also a failure.  So we just do it the way init scripts
# are expected to behave here.
start() {
        echo -n $”Starting $prog: “
        daemon $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch /var/lock/subsys/httpd
        return $RETVAL
}
stop() {
        echo -n $”Stopping $prog: “
        killproc $httpd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/httpd /var/run/httpd.pid
}
reload() {
        echo -n $”Reloading $prog: “
        killproc $httpd -HUP
        RETVAL=$?
        echo
}

# See how we were called.
case “$1″ in
  start)
        start
#        $apachectl startsslSSL を有効にする場合は上の start をコメントアウトして、この行を有効に
        RETVAL=$?
        ;;
  stop)
        stop
        ;;
  status)
        status $httpd
        RETVAL=$?
        ;;
  restart)
        stop
        start
#        $apachectl startsslSSL を有効にする場合は上の start をコメントアウトして、この行を有効に
        ;;
  condrestart)
        if [ -f /var/run/httpd.pid ] ; then
                stop
                start
        fi
        ;;
  reload)
        reload
        ;;
  graceful|help|configtest|fullstatus)
        $apachectl $@
        RETVAL=$?
        ;;
  *)
        echo $”Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}”
        exit 1
esac

exit $RETVAL

作成した自動起動スクリプトに実行権限を与えてサービスの登録を行います。

# chmod 755 /etc/rc.d/init.d/httpd
# chkconfig --add httpd

自動起動スクリプトを使って Apache を起動する場合は以下のように実行します。

# /etc/rc.d/init.d/httpd start

自動起動スクリプトのダウンロード » httpd

カテゴリー
  • Fedora のインストール (24)
  • OpenSSH で SSH サーバー構築 (4)
  • NTP で時刻情報サーバー構築 (4)
  • Apache HTTP Server で Web サーバー構築 (32)
  • MySQL でデーターベースサーバー構築 (10)
  • PostgreSQL でデーターベースサーバー構築 (22)
  • PHP で Web アプリケーションサーバー構築 (4)
  • qmail でメールサーバー構築 (7)
  • Tomcat で Web アプリケーションサーバー構築 (3)
  • Samba でファイルサーバー構築 (3)
  • BIND でネームサーバー構築 (3)
  • ProFTPD で FTP サーバー構築 (5)
  • snort でネットワーク進入探知システム構築 (3)
  • CMS でサイト構築 (3)
  • ネットワーク設定 (3)
  • システム設定 (4)
  • ライブラリのインストール (8)
  • Debian GNU/Linux (26)
  • Ubuntu (17)
  • メモ (6)
  • このサイトについて (4)
  • 相互リンク (6)