Webサーバ構築【Apache】【フリーソフト】
- 環境
OS:Ubuntu
バージョン:Server amd64 20.04.1 LTS
カーネル:5.4.0-52-generic
- 概要
フリーソフトで未だに存在感があり、多くの場所で利用されているWEBサーバの王道。様々なプラットフォームで利用できるようにMPMを採用しており、マルチスレッド対応のため少ないメモリ資源で多数の接続を受け入れる事が可能になっている。
- 構築
ソースコードのダウンロードおよびコンフィギュレーション
ここからwgetコマンドを利用して、最新版(httpd-2.4.46.tar.gz)をダウンロードします。
ubuntu@ubuntu:~$ wget https://ftp.yz.yamagata-u.ac.jp/pub/network/apache//httpd/httpd-2.4.46.tar.gz
ubuntu@ubuntu:~$ tar xvzf httpd-2.4.46.tar.gz
ubuntu@ubuntu:~$ cd httpd-2.4.46/
ubuntu@ubuntu:~/httpd-2.4.46$ ./configure --with-mpm=worker --prefix=/opt/www
checking for chosen layout... Apache
checking for working mkdir -p... yes
//
checking for APR... no
configure: error: APR not found. Please read the documentation.
APRがないと怒られたのでここから最新版(apr-1.6.5.tar.gz)を入れます。
ubuntu@ubuntu:~$ wget https://ftp.riken.jp/net/apache//apr/apr-1.6.5.tar.gz
ubuntu@ubuntu:~$ tar xvfz apr-1.6.5.tar.gz
ubuntu@ubuntu:~$ cd apr-1.6.5/
ubuntu@ubuntu:~/apr-1.6.5$ ./configure
checking build system type... armv7l-unknown-linux-gnueabihf
checking host system type... armv7l-unknown-linux-gnueabihf
//
checking for gcc... no
checking for cc... no
checking for cl.exe... no
コンパイラがないとのことなので、gccコンパイラをインストールします。
ubuntu@ubuntu:~/apr-1.6.5$ sudo apt install gcc
ubuntu@ubuntu:~/apr-1.6.5$ ./configure
ubuntu@ubuntu:~/apr-1.6.5$ make
Command 'make' not found, but can be installed with:
sudo apt install make # version 4.2.1-1.2, or
sudo apt install make-guile # version 4.2.1-1.2
今度は、makeコマンドがないとのことなのでmakeをインストールします。
ubuntu@ubuntu:~/apr-1.6.5$ sudo apt install make
気を取り直して
ubuntu@ubuntu:~/apr-1.6.5$ make
ubuntu@ubuntu:~/apr-1.6.5$ sudo make install
APRのインストールが成功したので、再度コンフィギュレーションを実施。
ubuntu@ubuntu:~/httpd-2.4.46$ ./configure --with-mpm=worker --prefix=/opt/www
checking for chosen layout... Apache
checking for working mkdir -p... yes
//
checking for APR-util... no
configure: error: APR-util not found. Please read the documentation.
APR-utilが足りなかったのでここから最新版(apr-util-1.6.1.tar.gz)を入れます。
ubuntu@ubuntu:~$ wget https://ftp.tsukuba.wide.ad.jp/software/apache//apr/apr-util-1.6.1.tar.gz
ubuntu@ubuntu:~$ tar xvzf apr-util-1.6.1.tar.gz
ubuntu@ubuntu:~$ cd apr-util-1.6.1/
ubuntu@ubuntu:~/apr-util-1.6.1$ ./configure
checking build system type... armv7l-unknown-linux-gnueabihf
checking host system type... armv7l-unknown-linux-gnueabihf
//
checking for APR... no
configure: error: APR could not be located. Please use the --with-apr option.
APRのディレクトリを指定しないといけないので、先ほどのAPRのディレクトリを指定して再度実行。
ubuntu@ubuntu:~/apr-util-1.6.1$ ./configure --with-apr=/home/ubuntu/apr-1.6.5
ubuntu@ubuntu:~/apr-util-1.6.1$ make
xml/apr_xml.c:35:10: fatal error: expat.h: No such file or directory
35 | #include <expat.h>
| ^~~~~~~~~
compilation terminated.
make: *** [/home/ubuntu/apr-util-1.6.1/build/rules.mk:206: xml/apr_xml.lo] Error 1
expatがないとのことなので、以下でインストールし再度実行
ubuntu@ubuntu:~/apr-util-1.6.1$ sudo apt install libexpat1-dev
ubuntu@ubuntu:~/apr-util-1.6.1$ make
ubuntu@ubuntu:~/apr-util-1.6.1$ sudo make install
ここで、警告が出てきましたが無視をします。
libtool: warning: relinking 'libaprutil-1.la'
再度実行すると、今度はPCREが入っていないとのこと。
ubuntu@ubuntu:~/httpd-2.4.46$ ./configure --with-mpm=worker --prefix=/opt/www
checking for chosen layout... Apache
checking for working mkdir -p... yes
//
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
ここからpcre-8.44.tar.gzをダウンロード・インストールします。
ubuntu@ubuntu:~$ wget ftp://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz
ubuntu@ubuntu:~$ tar xvfz pcre-8.44.tar.gz
ubuntu@ubuntu:~$ cd pcre-8.44/
ubuntu@ubuntu:~/pcre-8.44$ ./configure
//
configure: error: Invalid C++ compiler or C++ compiler flags
C++が入っていないとのことなのでインストールします。
ubuntu@ubuntu:~/pcre-8.44$ sudo apt install g++
やり直し
ubuntu@ubuntu:~/pcre-8.44$ ./configure
ubuntu@ubuntu:~/pcre-8.44$ make
ubuntu@ubuntu:~/pcre-8.44$ sudo make install
今度こそ
ubuntu@ubuntu:~/httpd-2.4.46$ ./configure --with-mpm=worker --prefix=/opt/www
ubuntu@ubuntu:~/httpd-2.4.46$ make
//
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:48: htpasswd] Error 1
make[2]: Leaving directory '/home/ubuntu/httpd-2.4.46/support'
make[1]: *** [/home/ubuntu/httpd-2.4.46/build/rules.mk:75: all-recursive] Error 1
make[1]: Leaving directory '/home/ubuntu/httpd-2.4.46/support'
make: *** [/home/ubuntu/httpd-2.4.46/build/rules.mk:75: all-recursive] Error 1
aprとapr-utilがバンドル出来ていないので、以下の通りする
ubuntu@ubuntu:~/httpd-2.4.46$ cp -a ../apr-1.6.5 srclib/apr
ubuntu@ubuntu:~/httpd-2.4.46$ cp -a ../apr-util-1.6.1 srclib/apr-util
ubuntu@ubuntu:~/httpd-2.4.46$ ./configure --with-mpm=worker --prefix=/opt/www --with-included-apr --with-included-apr-util
ubuntu@ubuntu:~/httpd-2.4.46$ make
ubuntu@ubuntu:~/httpd-2.4.46$ sudo make install
libpcre.so.1のリンクが張られていないので
ubuntu@ubuntu:~/pcre-8.44$ ldd /opt/www/bin/httpd
linux-vdso.so.1 (0x00007ffc613f2000)
libpcre.so.1 => not found
libaprutil-1.so.0 => /opt/www/lib/libaprutil-1.so.0 (0x00007f6976e81000)
libapr-1.so.0 => /opt/www/lib/libapr-1.so.0 (0x00007f6976e46000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f6976e23000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6976c31000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f6976c03000)
libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f6976bc6000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f6976bc0000)
/lib64/ld-linux-x86-64.so.2 (0x00007f6976f65000)
少し前にインストールしたpcreから拝借
ubuntu@ubuntu:~$ sudo ln -s /home/ubuntu/pcre-8.44/.libs/libpcre.so.1 /opt/www/lib/libpcre.so.1
ubuntu@ubuntu:~$ ldd /opt/www/bin/httpd
linux-vdso.so.1 (0x00007ffcedf31000)
libpcre.so.1 => /opt/www/lib/libpcre.so.1 (0x00007f81b6557000)
libaprutil-1.so.0 => /opt/www/lib/libaprutil-1.so.0 (0x00007f81b6529000)
libapr-1.so.0 => /opt/www/lib/libapr-1.so.0 (0x00007f81b64ee000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f81b64c4000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f81b62d2000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f81b62a4000)
libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f81b6267000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f81b6261000)
/lib64/ld-linux-x86-64.so.2 (0x00007f81b6626000)
いよいよ最後だが、httpd.confにServerNameが指定されていないのでエラーが発生するので追記
ubuntu@ubuntu:~$ sudo /opt/www/bin/apachectl
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
(13)Permission denied: AH00072: make_sock: could not bind to address [::]:80
(13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
/opt/www/conf/httpd.confにServerName 127.0.0.1:80を追記し再度起動
無事に起動
*1:Ver10は入れれません。