Cent OS 8にApache httpd2.4の最新版をソースからインストール

#はじめに
CentOS-8.1.1911-x86_64を「最低限のインストール」でインストールした環境にApacheの最新版をソースからインストールします。
SSL設定は除いております

#OS全体のupdate

```Bash
dnf -y update
```

#必要なソフトのインストール

```Bash
dnf -y install gcc gcc-c++ make wget tar systemd-devel perl libtool
```

#aprインストール
最新版確認 [http://apr.apache.org/](http://apr.apache.org/)

```Bash
cd /usr/local/src
wget http://ftp.meisei-u.ac.jp/mirror/apache/dist//apr/apr-1.7.0.tar.gz
tar xvzf apr-1.7.0.tar.gz
cd apr-1.7.0
./configure
make
make install
```

#Expat XML Parserインストール
最新版確認　[https://libexpat.github.io/](https://libexpat.github.io/)

```Bash
cd /usr/local/src
wget https://github.com/libexpat/libexpat/releases/download/R_2_2_9/expat-2.2.9.tar.gz
tar xvzf expat-2.2.9.tar.gz
cd expat-2.2.9
./configure
make
make install
```

#apr-utilインストール
最新版確認 [http://apr.apache.org/](http://apr.apache.org/)

```Bash
cd /usr/local/src
wget http://ftp.jaist.ac.jp/pub/apache//apr/apr-util-1.6.1.tar.gz
tar xvzf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1
./configure --with-apr=/usr/local/apr
make
make install
```

#PCREインストール
最新版確認　[https://www.pcre.org/](https://www.pcre.org/)

```Bash
cd /usr/local/src
wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz
tar xvzf pcre-8.44.tar.gz
cd pcre-8.44
./configure
make
make install
```

#zlibインストール
最新版確認　[https://www.zlib.net/](https://www.zlib.net/)

```Bash
cd /usr/local/src
wget http://zlib.net/zlib-1.2.11.tar.gz
tar xvzf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
make install
```

#Apacheインストール
最新版確認　[https://httpd.apache.org/](https://httpd.apache.org/)

```Bash
cd /usr/local/src/
wget http://ftp.jaist.ac.jp/pub/apache//httpd/httpd-2.4.43.tar.gz
tar xvzf httpd-2.4.43.tar.gz
cd httpd-2.4.43/

./configure --with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr \
--enable-mods-shared=reallyall \
--enable-proxy \
--enable-proxy-ajp \
--enable-dav \
--enable-dav-fs \
--enable-headers \
--enable-rewrite=shared \
--enable-deflate \
--with-pcre=/usr/local

make
make install
```

##apxsを使ってコンパイル

```Bash
cd /usr/local/src/httpd-2.4.43/modules/arch/unix
/usr/local/apache2/bin/apxs -c mod_systemd.c -I /usr/include/systemd/sd-daemon.h
```

##libtoolでの設定

```Bash
libtool \
--silent \
--mode=compile gcc -std=gnu99 -prefer-pic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong \
--param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_LARGEFILE64_SOURCE  -DLINUX -D_REENTRANT -D_GNU_SOURCE \
-pthread -I/usr/local/apache2/include -I/usr/local/apr/include/apr-1 -c -o mod_systemd.lo mod_systemd.c && touch mod_systemd.slo

libtool \
--silent \
--mode=link gcc -std=gnu99 -Wl,-z,relro,-z,now,-L/usr/lib64 -o mod_systemd.la -rpath /usr/local/apache2/modules -module -avoid-version mod_systemd.lo

libtool \
--silent \
--mode=link gcc -std=gnu99 -Wl,-z,relro,-z,now,-L/usr/lib64 -o mod_systemd.la -rpath /usr/local/apache2/modules -module -avoid-version mod_systemd.lo -lsystemd
```

##apxsを使ってコンパイル

```Bash
/usr/local/apache2/bin/apxs -i -a -n systemd mod_systemd.la
```

##httpd.service作成

```Bash
vi /usr/lib/systemd/system/httpd.service
```

```httpd.service
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)

[Service]
Type=forking
ExecStart=/usr/local/apache2/bin/apachectl start
ExecReload=/usr/local/apache2/bin/apachectl graceful
ExecStop=/usr/local/apache2/bin/apachectl stop

# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target
```

##バージョン確認

```Bash
/usr/local/apache2/bin/httpd -v
```
```Bash
Server version: Apache/2.4.43 (Unix)
Server built:   Apr 24 2020 20:01:27
```

#ファイヤーウォールの設定

```Bash
firewall-cmd --add-service=http --permanent
firewall-cmd --reload
```

#自動起動設定 & スタート

```Bash
systemctl daemon-reload
systemctl start httpd
systemctl enable httpd
```

##動作確認
```Bash
systemctl status httpd
```

```Bash
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2020-04-24 20:07:26 EDT; 30min ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 26056 (httpd)
    Tasks: 109 (limit: 23922)
   Memory: 17.9M
   CGroup: /system.slice/httpd.service
           ├─26056 /usr/local/apache2/bin/httpd -k start
           ├─26057 /usr/local/apache2/bin/httpd -k start
           ├─26058 /usr/local/apache2/bin/httpd -k start
           ├─26059 /usr/local/apache2/bin/httpd -k start
           └─26164 /usr/local/apache2/bin/httpd -k start
```

#ブラウザからの動作確認
http://lostname/
にアクセスして下さい。

以下の画面が表示されればOKです。

![Apache.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/591423/502618cb-9dd5-e39c-8793-e85597153e3d.jpeg)

#参考/出展
https://qiita.com/shadowhat/items/163ee5fdd56c51100e9e

https://www.smiyasaka.com/CentOS7.0_server21.html