CLOVER🍀

That was when it all began.

Apache 2.4をソースからインストール

仕事でPHPを使いそうなので、ちょっと環境でも作ってみようかな、と思いまして。

というわけで、まずはApacheのインストールから。そういえば、2.4系をインストールするのは、初めてだったりします。そして、割とハマったのでメモ。

まずはApache本体をダウンロードしまして…
http://httpd.apache.org/

解凍、configure。

$ tar -jxvf httpd-2.4.3.tar.bz2
$ cd httpd-2.4.3/
$ ./configure --prefix=/usr/local/apache-httpd/httpd-2.4.3
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... no
configure: error: APR not found.  Please read the documentation.

なんか、怒られましたね。APRがないって言ってるよ〜。

ちょっと調べてみると、Apache 2.4からはソースにAPRとAPR-utilが同梱されなくなったので、自分でインストールしなくてはいけないらしいです。

結局、今回は全部でこれだけインストールしました。

名前 バージョン ダウンロード先
Apache Httpd Server 2.4.3 http://httpd.apache.org/
Apache Runtime Runtime(APR) 1.4.6 http://apr.apache.org/
APR-util 1.5.1 http://apr.apache.org/
Perl Compatible Regular Expressions(PCRE) 8.31 http://pcre.org/

インストール先は、以下のルールとします。

/usr/local/[ソフトウェア名]/[ソフトウェア名-Version]
/usr/local/[ソフトウェア名]/current  # 現在使用中のバージョンへのシンボリックリンク

というわけで、それぞれインストール。APRとAPR-utilは、Apacheのsrclibに放り込んでもいいらしいのですが…

APR。

$ cd /usr/local/
$ sudo mkdir apr

...

$ tar -jxvf apr-1.4.6.tar.bz2 
$ cd apr-1.4.6/
$ ./configure --prefix=/usr/local/apr/apr-1.4.6
$ make
$ sudo make install

...

$ cd /usr/local/apr
$ ln -s apr-1.4.6 current

APR-util。

$ cd /usr/local/
$ sudo mkdir apr-util

...

$ tar -jxvf apr-util-1.5.1.tar.bz2 
$ cd apr-util-1.5.1/
$ ./configure --prefix=/usr/local/apr-util/apr-util-1.5.1 --with-apr=/usr/local/apr/current
$ make
$ sudo make install

...

$ cd /usr/local/apr-util/
$ sudo ln -s apr-util-1.5.1 current

PCRE。

$ cd /usr/local/
$ sudo mkdir pcre

...

$ tar -jxvf pcre-8.31.tar.bz2 
$ cd pcre-8.31/
$ ./configure --prefix=/usr/local/pcre/pcre-8.31
$ make
$ sudo make install

...

$ cd /usr/local/pcre/
$ sudo ln -s pcre-8.31 current

で、やっとApacheコンパイルへ。オプションは、PHPを使うこともあって以下のようにしておきました。あと、mod_rewriteとmod_proxyくらい使いたくなるでしょ。

$ cd /usr/local/
$ sudo mkdir apache-httpd

...

$ tar -jxvf httpd-2.4.3.tar.bz2
$ cd httpd-2.4.3/
$ ./configure --prefix=/usr/local/apache-httpd/httpd-2.4.3 --with-apr=/usr/local/apr/current --with-apr-util=/usr/local/apr-util/current --with-pcre=/usr/local/pcre/current --with-mpm=prefork --enable-mods-shared=most --enable-rewrite --enable-proxy-http
$ make
$ sudo make install

...

$ cd /usr/local/apache-httpd/
$ sudo ln -s httpd-2.4.3 current

config.niceより。

./configure \
--prefix=/usr/local/apache-httpd/httpd-2.4.3 \
--with-apr=/usr/local/apr/current \
--with-apr-util=/usr/local/apr-util/current \
--with-pcre=/usr/local/pcre/current \
--with-mpm=prefork \
--enable-mods-shared=most \
--enable-rewrite \
--enable-proxy-http"

とりあえず、httpd.confのServerNameとLoadModule(proxy、proxy_http、rewriteの有効化)だけ調節して…。

$ cd current
$ sudo vim conf/httpd.conf

確認。

$ ./bin/apachectl -V
Server version: Apache/2.4.3 (Unix)
Server built:   Nov 17 2012 22:31:56
Server's Module Magic Number: 20120211:6
Server loaded:  APR 1.4.6, APR-UTIL 1.5.1
Compiled using: APR 1.4.6, APR-UTIL 1.5.1
Architecture:   64-bit
Server MPM:     prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/usr/local/apache-httpd/httpd-2.4.3"
 -D SUEXEC_BIN="/usr/local/apache-httpd/httpd-2.4.3/bin/suexec"
 -D DEFAULT_PIDLOG="logs/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"
$ ./bin/apachectl -M
Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 mpm_prefork_module (static)
 authn_file_module (shared)
 authn_core_module (shared)
 authz_host_module (shared)
 authz_groupfile_module (shared)
 authz_user_module (shared)
 authz_core_module (shared)
 access_compat_module (shared)
 auth_basic_module (shared)
 reqtimeout_module (shared)
 filter_module (shared)
 mime_module (shared)
 log_config_module (shared)
 env_module (shared)
 headers_module (shared)
 setenvif_module (shared)
 version_module (shared)
 proxy_module (shared)
 proxy_http_module (shared)
 unixd_module (shared)
 status_module (shared)
 autoindex_module (shared)
 dir_module (shared)
 alias_module (shared)
 rewrite_module (shared)

起動。

$ sudo ./bin/apachectl start

確認。

$ telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /
<html><body><h1>It works!</h1></body></html>
Connection closed by foreign host.

OKですね。

オマケ)APRとAPR-utilをApacheと一緒にビルドする場合

とりあえず、それぞれアーカイブを展開します。

$ ll
合計 5884
drwxrwxr-x  5 xxxxx xxxxx    4096 Nov 18 01:41 ./
drwxr-xr-x  7 xxxxx xxxxx    4096 Nov 18 01:40 ../
drwxr-xr-x 25 xxxxx xxxxx    4096 Feb  8  2012 apr-1.4.6/
-rw-rw-r--  1 xxxxx xxxxx  785724 Nov 18 01:41 apr-1.4.6.tar.bz2
drwxr-xr-x 19 xxxxx xxxxx    4096 Sep  8 06:38 apr-util-1.5.1/
-rw-rw-r--  1 xxxxx xxxxx  652081 Nov 18 01:41 apr-util-1.5.1.tar.bz2
drwxr-xr-x 11 xxxxx xxxxx    4096 Aug 18 02:20 httpd-2.4.3/
-rw-rw-r--  1 xxxxx xxxxx 4559279 Nov 18 01:41 httpd-2.4.3.tar.bz2

Apacheのsrclibディレクトリ配下に、APRとAPR-utilを移動します。

$ mv apr-1.4.6 httpd-2.4.3/srclib/apr
$ mv apr-util-1.5.1 httpd-2.4.3/srclib/apr-util

この時、名前は変更しておきます。

そして、configure時には「--with-included-apr」を付与します。

$ ./configure --with-included-apr

その他、オプションはお好みで。