ソースインストールされたApacheでは、条件さえクリアしていれば、あとから手動でモジュールを追加することも可能です。
今回は、headerカスタマイズに使うモジュールを例に取って、手順を見てみます。
もしこのモジュールがないまま Hearderの記述をした場合は以下のエラーとなります。
[html]
Invalid command ‘Header’, perhaps misspelled or defined by a module not included in the server configuration
[/html]
【現状の確認】
[html]
$ /usr/local/apache2/bin/httpd -M
[/html]
headers_module
が含まれていない事を確認。 インストールが完了すると、これが入ります。
[html]
$ /usr/local/apache2/bin/httpd -l
[/html]
mod_so.c がある事を確認。これがないとモジュールの追加はできません。
httpdを最初からインストールし直す事になります。
【対象のモジュール】
モジュール headers_module
詳細はこちら(http://httpd.apache.org/docs/current/ja/mod/mod_headers.html)
【既存のバックアップ】
cp等で取っておくのが安全です。
[html]ソースのバックアップ
# cp -rp /usr/local/src/httpd-2.2.21 /usr/local/src/httpd-2.2.21_20141016
httpd.confのバックアップ
# cp -rp /usr/local/apache2/conf/httpd.conf /usr/local/apache2/conf/httpd.conf.2014101601
[/html]
では、モジュール追加と行きましょうか!
【コンパイル】
対象モジュールを探します。通常、module配下にあるので探しましょう。
移動して、
[html]cd /usr/local/src/httpd-2.2.21/modules/metadata/[/html]
apxsコマンドです。
ちなみに、オプションは以下です。
[html]
Usage: apxs -g [-S <var>=<val>] -n <modname>
apxs -q [-S <var>=<val>] <query> …
apxs -c [-S <var>=<val>] [-o <dsofile>] [-D <name>[=<value>]]
[-I <incdir>] [-L <libdir>] [-l <libname>] [-Wc,<flags>]
[-Wl,<flags>] [-p] <files> …
apxs -i [-S <var>=<val>] [-a] [-A] [-n <modname>] <dsofile> …
apxs -e [-S <var>=<val>] [-a] [-A] [-n <modname>] <dsofile> …
[/html]
これで実行。
[html]/usr/local/apache2/bin/apxs -c mod_headers.c
/usr/local/apache2/build/libtool –silent –mode=compile gcc -prefer-pic -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -g -O2 -pthread -I/usr/local/apache2/include -I/usr/local/apache2/include -I/usr/local/apache2/include -c -o mod_headers.lo mod_headers.c && touch mod_headers.slo
/usr/local/apache2/build/libtool –silent –mode=link gcc -o mod_headers.la -rpath /usr/local/apache2/modules -module -avoid-version mod_headers.lo
[/html]
完了。
【インストール】
以下を実行します。
[html]
/usr/local/apache2/bin/apxs -ian headers mod_headers.la
[/html]
結果
[html]
〜略〜
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
———————————————————————-
chmod 755 /usr/local/apache2/modules/mod_headers.so
[activating module `headers’ in /usr/local/apache2/conf/httpd.conf]
[/html]
自動でhttpd.confにモジュールも追加してくれた模様。
[html]
# diff /usr/local/apache2/conf/httpd.conf /usr/local/apache2/conf/httpd.conf.2014101601
55d54
< LoadModule headers_module modules/mod_headers.so
[/html]
diffするとありました。
【設定ファイルの読み込み】
[html]
# /etc/init.d/httpd graceful
[/html]
【インストールの確認】
[html]
$ /usr/local/apache2/bin/httpd -M
[/html]
headers_module (shared) が入ったのを確認!