前回はApacheをyumでインストールした。 yumでインストールすると簡単だし、起動するのに手間がかからないのだけど 個別にモジュールを入れたり、インストールしたいバージョンがなかったりするので不便な場合がある。 そういう時はソースからインストールするのが良い。 ソースからのインストールは基本的に以下の通りにやることが多い。
- wgetコマンドでソース(tar.gz or zip)をダウンロード
- tar or unzipコマンドで解凍
- ./configure で設定
- make -> make install
しかし、入れるアプリケーションによってconfigureでオプションを付けたり、必要なパッケージをyumでインストールしたりと試行錯誤しながらやるので面倒だったりする。 本やWebで調べながら実際にインストールをやって覚えるのが一番だと思う。
というわけで、Apacheをソースからインストールしていきます。 今回は、Apache 2.2.23, 2.4.2 をインストールしました。 2.2系と2.4系は若干インストール方法が異なるので注意!
- 必要なパッケージのインストール
- Apache Portable Runtim(APR)のインストール(2.4系の場合のみ) 2.2系の場合は、4.Apacheのインストール まで飛ばしてOK。
- ソースのダウンロード、解凍
- インストール
- APR-utilのインストール(2.4系の場合のみ)
- ソースのダウンロード、解凍
- インストール
- Apacheのインストール
- 2.4系の場合
- 2.2系の場合
- 起動確認
- 自動起動の設定
- 一度Apacheを停止する
- 起動スクリプトを編集する
- 自動起動の設定
- 確認
- Apache起動
$ sudo yum install openssl openssl-devel
$ wget http://ftp.riken.jp/net/apache//apr/apr-1.4.6.tar.gz
$ tar zxvf apr-1.4.6.tar.gz
最新版は、https://apr.apache.org/download.cgi から探す
$ cd apr-1.4.6
$ ./configure
$ make
$ sudo make install
$ wget http://ftp.riken.jp/net/apache//apr/apr-util-1.4.1.tar.gz
$ tar zxvf apr-util-1.4.1.tar.gz
最新版は、https://apr.apache.org/download.cgi から探す
$ cd apr-util-1.4.1
$ ./configure --with-apr=/usr/local/apr
$ make
$ sudo make install
with-aprオプションは、APRがインストールされているディレクトリのパスを指定する。
TABキーを押しながらやるとディレクトリ名を間違えずに済む。
$ wget http://ftp.meisei-u.ac.jp/mirror/apache/dist//httpd/httpd-2.4.2.tar.gz
$ tar zxvf httpd-2.4.2.tar.gz
最新版は、https://httpd.apache.org/download.cgi から探す
$ cd httpd-2.4.2
$ ./configure \
--enable-so \
--enable-ssl \
--enable-rewrite \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr
上記のオプションはDSO, SSL, mod_rewrite モジュールをApacheに組み込んでいる。
with-apr, with-apr-util オプションは、APR, APR-utilがインストールされているディレクトリのパスを指定する。
$ make
$ sudo make install
$ wget http://ftp.meisei-u.ac.jp/mirror/apache/dist//httpd/httpd-2.2.23.tar.gz
$ tar zxvf httpd2.2.23.tar.gz
$ cd httpd2.2.23
$ ./configure \
--prefix=/usr/local/apache2 \
--enable-ssl \
--enable-so \
--enable-rewrite \
--with-ssl=/usr \
--with-included-apr
$ make
$ sudo make install
$ sudo /usr/local/apache2/bin/apachectl start
「AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message」
と表示される場合はhttpd.confを編集する。
$ sudo vim /usr/local/apache2/conf/httpd.conf
# ServerName example.com:80
ServerName localhost:80 ←サーバーのホスト名
再起動する。
$ sudo /usr/local/apache2/bin/apachectl restart
何も表示されないのでプロセスを見て確認する
$ ps aux | grep httpd
root 14026 0.0 0.3 71340 3088 ? Ss 11:29 0:00 /usr/local/apache2/bin/httpd -k start
daemon 14124 0.1 0.4 415600 4536 ? Sl 11:31 0:00 /usr/local/apache2/bin/httpd -k start
daemon 14125 0.1 0.4 481136 5092 ? Sl 11:31 0:00 /usr/local/apache2/bin/httpd -k start
daemon 14126 0.1 0.4 415600 4544 ? Sl 11:31 0:00 /usr/local/apache2/bin/httpd -k start
root 14277 0.0 0.0 103244 800 pts/1 D+ 11:33 0:00 grep httpd
ブラウザからも確認する
http://サーバーのIPアドレス/
$ sudo /usr/local/apache2/bin/apachectl stop
$ cd [ソースを解凍したディレクトリ]/httpd-2.4.2
$ sudo install -m755 bulid/rpm/httpd.init /etc/rc.d/init.d/httpd
installコマンドはコピーだけではなく、アクセス権限や所有者などをファイルに設定できる。
$ sudo vim /etc/rc.d/init.d/httpd
以下を編集する
httpd=${HTTPD-/usr/sbin/httpd}
↓
httpd=${HTTPD-/usr/local/apache2/bin/httpd}
pidfile=${PIDFILE-/var/log/httpd/${prog}.pid}
↓
pidfile=${PIDFILE-/usr/local/apache2/logs/httpd.pid}
# check for 1.3 configuration
check13 () {
CONFFILE=/etc/httpd/conf/httpd.conf
↓
# check for 1.3 configuration
check13 () {
CONFFILE=/usr/local/apache2/conf/httpd.conf
$ sudo chkconfig --add httpd
$ sudo chkconfig httpd on
$ chkconfig --list httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
$ sudo /etc/rc.d/init.d/httpd start
Starting httpd: [ OK ]
インストール及び、自動起動の設定が完了した。 最後にメモ。
- ドキュメントルードは /usr/local/apache2/htdocs にある。
- 設定ファイルは /usr/local/apache2/conf にある。
- ログは /usr/local/apache2/logs にある(デフォルトはaccess_log, error_logのみ)。