パッケージ(yum)で入れればOKな世代(?)ですが、既にソースで動いているシステムを触らなければいけないこともあります。
ソースインストールはやったことがないな~ということで、今回はApache(httpd-2.4.23)のソースインストールをやっていきます。
なお、トライアル&エラーで回り道をしながらインストールします。
回り道をせず一発でインストールしたい場合は最下段「エラー無しでやる方法」をご覧下さい。
まずはソースファイルをダウンロード→解凍します。
# cd /usr/local/src # wget http://download.nextag.com/apache//httpd/httpd-2.4.23.tar.gz # tar xvzf httpd-2.4.23.tar.gz
インストール先を/usr/local/apache2としてconfigureスクリプトを実行します。
# cd httpd-2.4.23 # ./configure --prefix=/usr/local/apache2
すると下記のように「APRが無い」というエラーが発生しました。
checking for APR... no configure: error: APR not found. Please read the documentation.
Apacheに先んじてAPRをインストールします。
ソースファイルをダウンロード→解凍→configure。
# cd /usr/local/src # wget http://mirrors.ocf.berkeley.edu/apache//apr/apr-1.5.2.tar.gz # tar xvzf apr-1.5.2.tar.gz # cd apr-1.5.2 # ./configure
すると今度はCコンパイラが無いと言われます。
checking for gcc... no checking for cc... no checking for cl.exe... no configure: error: in `/usr/local/src/apr-1.5.2': configure: error: no acceptable C compiler found in $PATH
今回はあくまで「Apacheの」ソースインストールなので、細かい部分はyumでやってしまいます。
Cコンパイラ(gcc)をインストールしましょう。
# yum install gcc
再度APRをconfigureしてみましょう。
configureが正常終了したらコンパイル(make)→インストール(make install)。
(/usr/local/src/apr-1.5.2 内で) # ./configure # make # make install
これでAPRはインストールできたはずなので、再度Apacheをconfigureしてみます。
# cd /usr/local/src/httpd-2.4.23 # ./configure
次はARR-utilが無いというエラーが表示されました。
configure: checking for APR-util... no configure: error: APR-util not found. Please read the documentation.
APR-utilをダウンロード→解凍→configureします。
# cd /usr/local/src # wget http://mirrors.ocf.berkeley.edu/apache//apr/apr-util-1.5.4.tar.gz # tar xvzf apr-util-1.5.4.tar.gz # cd apr-util-1.5.4 # ./configure
configureに際して、次は下記のようなエラーメッセージが表示されました。
checking for APR... no configure: error: APR could not be located. Please use the --with-apr option.
–withaprオプションでARPのあるディレクトリを指定してくれとのことなので、その通りにconfigureします。
configureが正常終了したらコンパイル(make)→インストール(make install)。
(/usr/local/src/apr-util-1.5.4 内で) # ./configure --with-apr=/usr/local/src/apr-1.5.2 # make # make install
これでARP-utilも入ったはずなので再々度Apacheをconfigureしてみます。
# cd /usr/local/src/httpd-2.4.23 # ./configure
今度はPCREが足りないと言われてしまいました。
checking for pcre-config... false configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
PCREをダウンロード→解凍→configure→コンパイル(make)→インストール(make install)。
# cd /usr/local/src # wget https://sourceforge.net/projects/pcre/files/pcre2/10.22/pcre2-10.22.tar.gz # tar xvzf pcre2-10.22.tar.gz # cd pcre2-10.22 # ./configure # make # make install
PCREのインストールされている場所を指定して再々々度Apacheをconfigureしてみます。
# cd /usr/local/src/httpd-2.4.23 # ./configure --with-pcre=/usr/local/src/pcre2-10.22/pcre2-config # make
コンパイル(make)の時点で下記エラーが発生しました。
util_pcre.c:49:18: fatal error: pcre.h: No such file or directory
下記サイトによると、どうやらPCREはバージョン8までしかダメだそう。
Re: Install Apache 2.4.20 on Solaris 10 — Error “ld: fatal: file ab.o: wrong ELF class: ELFCLASS32”
名残惜しいですがpcre2-10は消します。
# cd /usr/local/src/pcre2-10.22 # make uninstall # cd .. # rm -rf pcre2-10.22 # rm pcre2-10.22.tar.gz
代わりにバージョン8の最新版(pcre-8.39)をインストールしてみる。
# wget https://sourceforge.net/projects/pcre/files/pcre/8.39/pcre-8.39.tar.gz # tar xvzf pcre-8.39.tar.gz # cd pcre-8.39 # ./configure
configureで下記エラーが発生しました。
configure: error: You need a C++ compiler for C++ support.
C++コンパイラ(gcc-c++)が無いと言われたのでインストールします。
# yum install gcc-c++
再度PCREをconfigureします。
正常終了したらコンパイル(make)→インストール(make install)。
(/usr/local/src/pcre-8.39 内で) # ./configure # make # make install
どうやらPCRE(8.39)が正常にインストールできたようです。
ここまで回り道をしていると本来の目的を忘れそうになりますが…。
PCREのインストールされている場所(変わりました)を指定して再々々々度Apacheをconfigureしてみます。
正常終了したらコンパイル(make)→インストール(make install)。
# cd /usr/local/src/httpd-2.4.23 # ./configure --with-pcre=/usr/local/src/pcre-8.39/pcre-config # make # make install
どうやら、ようやくApacheがインストールされたようです。
Apache起動スクリプトをコピーで作成します。
# cp -ip /usr/local/src/httpd-2.4.23/build/rpm/httpd.init /etc/init.d/httpd
また、Apache起動・停止時にファイルが無い等と言われてしまうので起動スクリプトを編集しておきます。
# vi /etc/init.d/httpd httpd=${HTTPD-/usr/local/apache2/bin/httpd} pidfile=${PIDFILE-/usr/local/apache2/logs/httpd.pid} CONFFILE=/usr/local/apache2/conf/httpd.conf
パッケージインストールのようにapacheユーザでhttpdプロセスを実行したい場合:
confファイルへの記載と、apacheユーザの追加(※)を行います。
※GID/UIDもパッケージインストール時と合わせています。
# vi /usr/local/apache2/conf/httpd.conf User apache Group apache # groupadd -g 48 apache # useradd -g apache -u 48 apache
ではApacheを起動して、
# /etc/init.d/httpd start
ブラウザでアクセスしてみましょう。
http://サーバのIP
下記のように It works! と表示されます。

Webサーバ機能が使えるようになったということで、これにてひと段落。
最後に自動起動設定も加えて、完了!
# chkconfig --add httpd # chkconfig httpd on
■エラー無しでやる方法
・APRインストール
# yum install gcc # cd /usr/local/src # wget http://mirrors.ocf.berkeley.edu/apache//apr/apr-1.5.2.tar.gz # tar xvzf apr-1.5.2.tar.gz # cd apr-1.5.2 # ./configure # make # make install
・APR-utilインストール
# cd /usr/local/src # wget http://mirrors.ocf.berkeley.edu/apache//apr/apr-util-1.5.4.tar.gz # tar xvzf apr-util-1.5.4.tar.gz # cd apr-util-1.5.4 # ./configure --with-apr=/usr/local/src/apr-1.5.2 # make # make install
・PCREインストール
# yum install gcc-c++ # cd /usr/local/src # wget https://sourceforge.net/projects/pcre/files/pcre/8.39/pcre-8.39.tar.gz # tar xvzf pcre-8.39.tar.gz # cd pcre-8.39 # ./configure # make # make install
・Apacheインストール
# cd /usr/local/src # wget http://download.nextag.com/apache//httpd/httpd-2.4.23.tar.gz # tar xvzf httpd-2.4.23.tar.gz # cd httpd-2.4.23 # ./configure --with-pcre=/usr/local/src/pcre-8.39/pcre-config # make # make install
・Apache:起動スクリプト、設定ファイル調整
# cp -ip /usr/local/src/httpd-2.4.23/build/rpm/httpd.init /etc/init.d/httpd # vi /etc/init.d/httpd httpd=${HTTPD-/usr/local/apache2/bin/httpd} pidfile=${PIDFILE-/usr/local/apache2/logs/httpd.pid} CONFFILE=/usr/local/apache2/conf/httpd.conf # vi /usr/local/apache2/conf/httpd.conf User apache Group apache # groupadd -g 48 apache # useradd -g apache -u 48 apache # chkconfig --add httpd # chkconfig httpd on
投稿者プロフィール
- 2015年8月入社。弊社はインフラ屋ですが、アプリも作ってみたいです。