CentOS7のApache最新版アップデート

VPSのCentOS7.9にインストールしているApacheを最新バージョン2.4.46(2020.8.7release)にアップデート

CentOS7をインストールした際のApacheのデフォルトバージョンは、2.4.6となり、標準リポジトリでは、以降のバージョンにアップデートされません。
最新バージョンのパッケージをインストールするためにはIUSリポジトリを追加する必要があります。

◆リポジトリの追加

必要なリポジトリとして、EPEL及びIUSが必要になりますので追加します。

・EPELリポジトリ

EPELリポジトリはインストール済みだったので、省略
追加する場合は、以下のコマンドでインストールします。

# yum -y install epel-release
・IUSリポジトリ
# yum -y install https://repo.ius.io/ius-release-el7.rpm
読み込んだプラグイン:langpacks, versionlock
ius-release-el7.rpm                               | 8.2 kB  00:00:00

~ 中略 ~

  インストール中         : ius-release-2-1.el7.ius.noarch         1/1
  検証中                : ius-release-2-1.el7.ius.noarch         1/1

インストール:
  ius-release.noarch 0:2-1.el7.ius

完了しました!

1行目:yumでIUSリポジトリを追加インストール

・IUSリポジトリの無効化
# vi /etc/yum.repos.d/ius.repo
[ius]
name = IUS for Enterprise Linux 7 - $basearch
baseurl = https://repo.ius.io/7/$basearch/
enabled = 0
repo_gpgcheck = 0
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-IUS-7

5行目:「enabled」の設定値を「1」の有効から「0」の無効に変更し、必要時のみ有効にして使用する

◆httpdの削除

・サービスの停止
# systemctl stop httpd

1行目:httpdサービスを停止

・httpd関連パッケージを削除
# yum remove httpd*
読み込んだプラグイン:langpacks, versionlock
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ httpd.x86_64 0:2.4.6-97.el7.centos を 削除

~ 中略 ~

依存性を解決しました

==========================================================================================================================
 Package                            アーキテクチャー   バージョン                           リポジトリー             容量
==========================================================================================================================
削除中:
 httpd                              x86_64             2.4.6-97.el7.centos                  @updates                9.4 M
 httpd-devel                        x86_64             2.4.6-97.el7.centos                  @updates                752 k
 httpd-tools                        x86_64             2.4.6-97.el7.centos                  @updates                168 k
依存性関連での削除をします:
 mod_perl                           x86_64             2.0.11-1.el7                         @epel                   6.2 M
 mod_ssl                            x86_64             1:2.4.6-97.el7.centos                @updates                224 k
 php                                x86_64             7.4.21-1.el7.remi                    @remi-php74              10 M
 python2-certbot-apache             noarch             1.11.0-1.el7                         @epel                   578 k

トランザクションの要約
==========================================================================================================================
削除  3 パッケージ (+4 個の依存関係のパッケージ)

インストール容量: 27 M
上記の処理を行います。よろしいでしょうか? [y/N]y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  削除中                  : python2-certbot-apache-1.11.0-1.el7.noarch                                                1/7
  削除中                  : 1:mod_ssl-2.4.6-97.el7.centos.x86_64                                                      2/7
警告: /etc/httpd/conf.d/ssl.conf は /etc/httpd/conf.d/ssl.conf.rpmsave として保存されました。
  削除中                  : httpd-devel-2.4.6-97.el7.centos.x86_64                                                    3/7
  削除中                  : mod_perl-2.0.11-1.el7.x86_64                                                              4/7
  削除中                  : php-7.4.21-1.el7.remi.x86_64                                                              5/7
  削除中                  : httpd-2.4.6-97.el7.centos.x86_64                                                          6/7
警告: /etc/logrotate.d/httpd は /etc/logrotate.d/httpd.rpmsave として保存されました。
警告: /etc/httpd/conf/httpd.conf は /etc/httpd/conf/httpd.conf.rpmsave として保存されました。
警告: /etc/httpd/conf.d/userdir.conf は /etc/httpd/conf.d/userdir.conf.rpmsave として保存されました。
警告: /etc/httpd/conf.d/autoindex.conf は /etc/httpd/conf.d/autoindex.conf.rpmsave として保存されました。

~ 中略 ~

削除しました:
  httpd.x86_64 0:2.4.6-97.el7.centos  httpd-devel.x86_64 0:2.4.6-97.el7.centos  httpd-tools.x86_64 0:2.4.6-97.el7.centos

依存性の削除をしました:
  mod_perl.x86_64 0:2.0.11-1.el7                 mod_ssl.x86_64 1:2.4.6-97.el7.centos   php.x86_64 0:7.4.21-1.el7.remi
  python2-certbot-apache.noarch 0:1.11.0-1.el7

完了しました!

1行目:「httpd*」で関連パッケージを含めて削除
19~22行目:依存性関連で削除されたパッケージに関しては新バージョンのhttpdインストール時に再度追加する必要があるのでテキストなどにコピーしておく
37,42~45行目:「警告」にあるように各設定ファイルのバックアップが作成されているので、インストール後に設定ファイルの変更で使用する

◆インストール

・httpdのインストール
# yum install --disablerepo=base,extras,updates --enablerepo=ius httpd
読み込んだプラグイン:langpacks, versionlock
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ httpd24u.x86_64 0:2.4.46-1.el7.ius を インストール

~ 中略 ~

依存性を解決しました

==========================================================================================================================
 Package                             アーキテクチャー       バージョン                         リポジトリー          容量
==========================================================================================================================
インストール中:
 httpd24u                            x86_64                 2.4.46-1.el7.ius                   ius                  1.4 M
依存性関連でのインストールをします:
 apr15u                              x86_64                 1.5.2-2.ius.el7                    ius                  112 k
 apr15u-util                         x86_64                 1.5.4-3.ius.el7                    ius                   93 k
 brotli                              x86_64                 1.0.7-5.el7                        epel                 318 k
 httpd24u-filesystem                 noarch                 2.4.46-1.el7.ius                   ius                   27 k
 httpd24u-tools                      x86_64                 2.4.46-1.el7.ius                   ius                   91 k
 libnghttp2                          x86_64                 1.33.0-1.1.el7                     epel                  68 k

トランザクションの要約
==========================================================================================================================
インストール  1 パッケージ (+6 個の依存関係のパッケージ)

総ダウンロード容量: 2.1 M
インストール容量: 6.5 M
Is this ok [y/d/N]: y
Downloading packages:
(1/7): brotli-1.0.7-5.el7.x86_64.rpm                                                               | 318 kB  00:00:00
warning: /var/cache/yum/x86_64/7/ius/packages/apr15u-1.5.2-2.ius.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 4b274df2: NOKEY
apr15u-1.5.2-2.ius.el7.x86_64.rpm の公開鍵がインストールされていません
(2/7): apr15u-1.5.2-2.ius.el7.x86_64.rpm                                                           | 112 kB  00:00:00
(3/7): apr15u-util-1.5.4-3.ius.el7.x86_64.rpm                                                      |  93 kB  00:00:00
(4/7): httpd24u-filesystem-2.4.46-1.el7.ius.noarch.rpm                                             |  27 kB  00:00:00
(5/7): libnghttp2-1.33.0-1.1.el7.x86_64.rpm                                                        |  68 kB  00:00:00
(6/7): httpd24u-tools-2.4.46-1.el7.ius.x86_64.rpm                                                  |  91 kB  00:00:00
(7/7): httpd24u-2.4.46-1.el7.ius.x86_64.rpm                                                        | 1.4 MB  00:00:00
--------------------------------------------------------------------------------------------------------------------------
合計                                                                                      2.4 MB/s | 2.1 MB  00:00:00
file:///etc/pki/rpm-gpg/RPM-GPG-KEY-IUS-7 から鍵を取得中です。
Importing GPG key 0x4B274DF2:
 Userid     : "IUS (7) <dev@ius.io>"
 Fingerprint: c958 7a09 a11f d706 4f0c a0f4 e558 0725 4b27 4df2
 Package    : ius-release-2-1.el7.ius.noarch (@/ius-release-el7)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-IUS-7
上記の処理を行います。よろしいでしょうか? [y/N]y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : apr15u-1.5.2-2.ius.el7.x86_64                                                             1/7
  インストール中          : apr15u-util-1.5.4-3.ius.el7.x86_64                                                        2/7
  インストール中          : httpd24u-tools-2.4.46-1.el7.ius.x86_64                                                    3/7
  インストール中          : libnghttp2-1.33.0-1.1.el7.x86_64                                                          4/7
  インストール中          : brotli-1.0.7-5.el7.x86_64                                                                 5/7
  インストール中          : httpd24u-filesystem-2.4.46-1.el7.ius.noarch                                               6/7
  インストール中          : httpd24u-2.4.46-1.el7.ius.x86_64                                                          7/7
  検証中                  : httpd24u-tools-2.4.46-1.el7.ius.x86_64                                                    1/7
  検証中                  : httpd24u-filesystem-2.4.46-1.el7.ius.noarch                                               2/7
  検証中                  : httpd24u-2.4.46-1.el7.ius.x86_64                                                          3/7
  検証中                  : brotli-1.0.7-5.el7.x86_64                                                                 4/7
  検証中                  : apr15u-util-1.5.4-3.ius.el7.x86_64                                                        5/7
  検証中                  : apr15u-1.5.2-2.ius.el7.x86_64                                                             6/7
  検証中                  : libnghttp2-1.33.0-1.1.el7.x86_64                                                          7/7

インストール:
  httpd24u.x86_64 0:2.4.46-1.el7.ius

依存性関連をインストールしました:
  apr15u.x86_64 0:1.5.2-2.ius.el7                           apr15u-util.x86_64 0:1.5.4-3.ius.el7
  brotli.x86_64 0:1.0.7-5.el7                               httpd24u-filesystem.noarch 0:2.4.46-1.el7.ius
  httpd24u-tools.x86_64 0:2.4.46-1.el7.ius                  libnghttp2.x86_64 0:1.33.0-1.1.el7

完了しました!

1行目:標準リポジトリを無効にし、iusリポジトリを使用してhttpdをインストール

次に依存性関係でインストールされたパッケージの他、必要なパッケージをインストールしていきます。

・必要パッケージのインストール
# yum install --disablerepo=base,extras,updates --enablerepo=ius httpd-devel mod_ssl
読み込んだプラグイン:langpacks, versionlock
依存性の解決をしています

~ 中略 ~

依存性を解決しました

==========================================================================================================================
 Package                           アーキテクチャー       バージョン                            リポジトリー         容量
==========================================================================================================================
インストール中:
 httpd24u-devel                    x86_64                 2.4.46-1.el7.ius                      ius                 209 k
 httpd24u-mod_ssl                  x86_64                 1:2.4.46-1.el7.ius                    ius                 118 k
依存性関連でのインストールをします:
 apr15u-devel                      x86_64                 1.5.2-2.ius.el7                       ius                 194 k
 apr15u-util-devel                 x86_64                 1.5.4-3.ius.el7                       ius                  77 k

トランザクションの要約
==========================================================================================================================
インストール  2 パッケージ (+2 個の依存関係のパッケージ)

総ダウンロード容量: 598 k
インストール容量: 2.1 M
Is this ok [y/d/N]: y
Downloading packages:
(1/4): apr15u-devel-1.5.2-2.ius.el7.x86_64.rpm                                                     | 194 kB  00:00:00
(2/4): httpd24u-devel-2.4.46-1.el7.ius.x86_64.rpm                                                  | 209 kB  00:00:00
(3/4): apr15u-util-devel-1.5.4-3.ius.el7.x86_64.rpm                                                |  77 kB  00:00:00
(4/4): httpd24u-mod_ssl-2.4.46-1.el7.ius.x86_64.rpm                                                | 118 kB  00:00:00
--------------------------------------------------------------------------------------------------------------------------
合計                                                                                      638 kB/s | 598 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : apr15u-devel-1.5.2-2.ius.el7.x86_64                                                       1/4
  インストール中          : apr15u-util-devel-1.5.4-3.ius.el7.x86_64                                                  2/4
  インストール中          : httpd24u-devel-2.4.46-1.el7.ius.x86_64                                                    3/4
  インストール中          : 1:httpd24u-mod_ssl-2.4.46-1.el7.ius.x86_64                                                4/4
  検証中                  : apr15u-devel-1.5.2-2.ius.el7.x86_64                                                       1/4
  検証中                  : 1:httpd24u-mod_ssl-2.4.46-1.el7.ius.x86_64                                                2/4
  検証中                  : httpd24u-devel-2.4.46-1.el7.ius.x86_64                                                    3/4
  検証中                  : apr15u-util-devel-1.5.4-3.ius.el7.x86_64                                                  4/4

インストール:
  httpd24u-devel.x86_64 0:2.4.46-1.el7.ius                   httpd24u-mod_ssl.x86_64 1:2.4.46-1.el7.ius

依存性関連をインストールしました:
  apr15u-devel.x86_64 0:1.5.2-2.ius.el7                     apr15u-util-devel.x86_64 0:1.5.4-3.ius.el7

完了しました!

1行目:iusリポジトリから「httpd-devel」「mod_ssl」をインストール

# yum install php
読み込んだプラグイン:langpacks, versionlock
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ php.x86_64 0:7.4.21-1.el7.remi を インストール
--> 依存性解決を終了しました。

依存性を解決しました

==========================================================================================================================
 Package               アーキテクチャー         バージョン                             リポジトリー                  容量
==========================================================================================================================
インストール中:
 php                   x86_64                   7.4.21-1.el7.remi                      remi-php74                   3.4 M

トランザクションの要約
==========================================================================================================================
インストール  1 パッケージ

総ダウンロード容量: 3.4 M
インストール容量: 10 M
Is this ok [y/d/N]: y
Downloading packages:
php-7.4.21-1.el7.remi.x86_64.rpm                                                                   | 3.4 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : php-7.4.21-1.el7.remi.x86_64                                                              1/1
  検証中                  : php-7.4.21-1.el7.remi.x86_64                                                              1/1

インストール:
  php.x86_64 0:7.4.21-1.el7.remi

完了しました!

1行目:httpdを削除した際に依存関係で一緒に削除された「php」をインストール

phpのインストールするバージョンによって、リポジトリを導入や指定をする必要があります。
前回PHP7.4をインストールした際の記事を参考にしてください。「PHPのアップデート

同様に「mod_perl」「python2-certbot-apache」をインストール

・nghttp2のインストール
# yum install nghttp2
読み込んだプラグイン:langpacks, versionlock
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ nghttp2.x86_64 0:1.33.0-1.1.el7 を インストール

~ 中略 ~

インストール:
  nghttp2.x86_64 0:1.33.0-1.1.el7

依存性関連をインストールしました:

~ 中略 ~

完了しました!

1行目:「nghttpd2」をepelリポジトリからインストール

依存性関連で必要なパッケージは追加されると思いますが、足りないものがあった場合は、適宜追加します。

「nghttp2」パッケージは、「HTTP/2」を使用するためのコアエンジンで、Webサイト表示速度の高速化技術です。
下記リンクにHTTP/2についての記事が図解入りであったので参考にしてください。

カゴヤのサーバー研究室「【図解】HTTP/2って?HTTP/1.1との違いと導入メリット・課題まとめ

◆設定

・設定ファイルの変更

「httpd関連パッケージを削除」の項目で前述したとおり、各confファイルがバックアップ(.conf.rpmsaveの名前)されているので、「diff」コマンドを利用しながら追加・変更等をしていきます。

私の場合、下記の設定ファイルが対象でした。

/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/ssl.conf
/etc/logrotate.d/httpd
・設定ファイルの構文チェック
# httpd -t
Syntax OK

# apachectl configtest
Syntax OK

# service httpd configtest
Syntax OK

何れかのコマンドで設定ファイルのエラーチェックができるので確認します。

◆httpdの起動

・自動起動設定と確認
# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
# systemctl is-enabled httpd
enabled

1行目:自動起動設定し、サーバ起動時にサービスが自動で起動するように設定する
3行目:自動起動設定確認
4行目:「enabled」有効、「disabled」無効

・起動
# systemctl start httpd

1行目:httpdを起動する

◆動作確認

・httpdの状態確認
# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since 土 2021-07-10 19:26:23 JST; 10s ago
     Docs: man:httpd.service(8)
 Main PID: 26052 (/usr/sbin/httpd)
   Status: "Total requests: 0; Idle/Busy workers 100/0;Requests/sec: 0; Bytes served/sec:   0 B/sec"
   CGroup: /system.slice/httpd.service
           tq26052 /usr/sbin/httpd -DFOREGROUND
           tq26053 /usr/sbin/httpd -DFOREGROUND
           tq26058 /usr/sbin/httpd -DFOREGROUND
           tq26076 /usr/sbin/httpd -DFOREGROUND
           tq26085 /usr/sbin/httpd -DFOREGROUND
           mq26092 /usr/sbin/httpd -DFOREGROUND

 7月 10 19:26:23 marusv.maruweb.jp.net systemd[1]: Starting The Apache HTTP Server...
 7月 10 19:26:23 marusv.maruweb.jp.net httpd[26052]: [Sat Jul 10 19:26:23.811531 2021] [so:warn] [pid 26052:tid...ping
 7月 10 19:26:23 marusv.maruweb.jp.net systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

1行目:statusで状態確認する
2行目:「」が緑色
4行目:「Active」が「active (running)」と緑色で表示されていれば問題なし

・表示確認

ブラウザでWebサイトにアクセスし、正常に表示されることを確認します。

バージョンアップをする際には、サービス停止してからインストール、設定ファイルの変更等、サービス起動と時間を要することになり、更にエラーや不具合が起きた場合、サービスのダウンタイムが長くなることがあることを承知の上で実施する必要があります。

いいね! & シェア お願いします。

コメントは受け付けていません。