CentOS5, CentOS6で以下の動作確認を行いました。
CentOS(Red Hat系)でApacheをインストールしてPCの電源投入時に自動起動する方法を記述します。
また、コマンドによるApacheの起動・停止・再起動も記述します。
当方、CentOSをインストールした時、すでにApacheがインストールされていました。
以下にApacheがインストールされているかどうか確認することができるコマンドを記述します。
rpm -qa | grep httpd
上記のコマンドを実行し以下のように表示された場合は、ApacheのRPMパッケージがインストールされています。
$ rpm -qa | grep httpd httpd-tools-2.2.15-15.el6.centos.1.x86_64 httpd-2.2.15-15.el6.centos.1.x86_64
$ rpm -qa | grep httpd httpd-2.2.3-63.el5.centos.1以上のようにhttpd-バージョン...のように表示されればApache(httpd)はインストールされています。
yum install httpdもし、以下のようなメッセージが表示された場合は、Apache(root)はインストール済みでです。
# yum install httpd Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile * base: www.ftp.ne.jp * extras: www.ftp.ne.jp * updates: www.ftp.ne.jp Setting up Install Process Package httpd-2.2.15-15.el6.centos.1.x86_64 already installed and latest version Nothing to do
already installed and latest version Nothing to doと表示されています。
CentOSでは、以下のコマンドでApacheの起動・停止・再起動ができます。
rootユーザで以下のコマンドを実行してください。
service httpd startまたは
/etc/init.d/httpd start
service httpd stopまたは
/etc/init.d/httpd stop
service httpd restartまたは
/etc/init.d/httpd restart
chkconfigコマンドにより自動起動の設定をすることができます。
chkconfig --list | grep httpd httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off全てのランレベルがoffになっているため、Apache(httpd)は自動起動しません。
chkconfig httpd on以下、上記のコマンドを実行した後、設定状態を確認した実行結果です。
[root@centos6 ~]# chkconfig httpd on [root@centos6 ~]# chkconfig --list | grep httpd httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:offランレベル2から5の間でonになりました。
chkconfig httpd off以下、上記のコマンドを実行した後、設定状態を確認した実行結果です。
[root@centos6 ~]# chkconfig httpd off [root@centos6 ~]# chkconfig --list | grep httpd httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off全てのランレベルがoffになっているため、Apache(httpd)は自動起動しません。
以上、CentOSのApacheのインストールと自動起動設定について記述しました。