CentOSにApach2をパッケージインストールする
CentOS 7.2にて実行。
# yum -y install httpd
Apacheの起動/停止/再起動
# /usr/sbin/apachectl start ※起動 # /usr/sbin/apachectl stop ※停止 # /usr/sbin/apachectl restart ※再起動
Apacheがちゃんと起動したか確認。
以下のコマンドを入力して、/usr/sbin/httpdがずらっと表示されればOK。
# ps ax | grep httpd 2188 ? Ss 0:00 /usr/sbin/httpd -DFOREGROUND 2189 ? S 0:00 /usr/sbin/httpd -DFOREGROUND 2190 ? S 0:00 /usr/sbin/httpd -DFOREGROUND 2191 ? S 0:00 /usr/sbin/httpd -DFOREGROUND 2192 ? S 0:00 /usr/sbin/httpd -DFOREGROUND 2193 ? S 0:00 /usr/sbin/httpd -DFOREGROUND 2197 pts/1 R+ 0:00 grep --color=auto httpd
Apacheの自動起動設定。
# chkconfig httpd on 情報:'systemctl enable httpd.service'へ転送しています。 Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
自動起動解除
# chkconfig httpd off 情報:'systemctl disable httpd.service'へ転送しています。 Removed symlink /etc/systemd/system/multi-user.target.wants/httpd.service.
Apache2のソースインストール
あらかじめ、コンパイラをインストールしておいてください。
OpenSSLヘッダファイルのインストール
$ sudo yum -y install openssl-devel
PCREのインストール
$ sudo yum -y install pcre-devel
※既にインストールされている場合は、何もしません。
APR/APR-utilのインストール
Apache Portable RuntimeからAPRとAPR-utilのソースファイルをダウンロードし、適当なディレクトリに置いてください。
»ダウンロードページ
以下の手順に従って、インストールを行ってください。
$ tar xvzf apr-1.5.2.tar.gz $ cd apr-1.5.2 $ ./configure $ make $ sudo make install
$ tar xvzf apr-util-1.5.4.tar.gz $ cd apr-util-1.5.4 $ ./configure --with-apr=/usr/local/apr $ make $ sudo make install
Apache2用アカウントの作成
$ sudo /usr/sbin/groupadd apache $ sudo /usr/sbin/useradd -g apache -d /usr/local/apache -s /sbin/nologin apache
Apache2のコンパイルとインストールを行ってください。(» ダウンロードページ)
$ tar xvzf httpd-2.4.18.tar.gz $ cd httpd-2.4.18 $ ./configure --enable-so --enable-ssl --enable-modules=rewrite \ --prefix=/usr/local/apache $ make $ sudo make install
Apache2ディレクトリのパーミッションを変更して、外部からアクセスできるようにします。
$ sudo chmod 755 /usr/local/apache
Apacheの起動/停止/再起動
$ sudo /usr/local/apache/bin/apachectl start ※起動 $ sudo /usr/local/apache/bin/apachectl stop ※停止 $ sudo /usr/local/apache/bin/apachectl restart ※再起動
※起動の際、「Could not reliably determine the server’s fully qualified domain name, ~」なるメッセージが出て気になる場合は、/usr/local/apache/conf/httpd.confに以下の行を記述してください。
ServerName localhost:80
Apacheの自動起動設定。
$ cd Apacheのソースディレクトリ $ sudo cp build/rpm/httpd.init /etc/rc.d/init.d/httpd $ sudo chmod 755 /etc/rc.d/init.d/httpd
/etc/rc.d/init.d/httpdを修正します。
(修正前)
httpd=${HTTPD-/usr/sbin/httpd} #60行目付近 pidfile=${PIDFILE-/var/run/${prog}.pid} #61行目付近 CONFFILE=/etc/httpd/conf/httpd.conf #67行目付近
(修正後)
httpd=${HTTPD-/usr/local/apache/bin/httpd} pidfile=${PIDFILE-/var/run/httpd.pid} CONFFILE=/usr/local/apache/conf/httpd.conf
/usr/local/apache/conf/httpd.confに以下の行を追加してください。
PidFile /var/run/httpd.pid
Apache2を起動サービスに登録します。
$ sudo chkconfig httpd on
以上で、OS起動時にApache2が自動起動するようになります。
自動起動設定後は、以下のコマンドでApache2の起動/停止/再起動ができます。
# service httpd start # service httpd stop # service httpd stop