LoginSignup
22
14

More than 3 years have passed since last update.

CentOS8にApache(httpd)をインストールする方法

Last updated at Posted at 2019-12-30

CentOS8dnfコマンドを使用して速攻でApache(httpd)をインストールする方法を紹介します。

環境

  • OS:CentOS Linux release 8.0.1905

1. Apache(httpd)の確認

以下のコマンドでインストール対象(httpd)のパッケージを確認します。
dnf list | grep httpd

[root@CENTOS8 ~]# dnf list | grep httpd
centos-logos-httpd.noarch                            80.5-2.el8                                              AppStream
httpd.x86_64                                         2.4.37-12.module_el8.0.0+185+5908b0db                   AppStream
httpd-devel.x86_64                                   2.4.37-12.module_el8.0.0+185+5908b0db                   AppStream
httpd-filesystem.noarch                              2.4.37-12.module_el8.0.0+185+5908b0db                   AppStream
httpd-manual.noarch                                  2.4.37-12.module_el8.0.0+185+5908b0db                   AppStream
httpd-tools.x86_64                                   2.4.37-12.module_el8.0.0+185+5908b0db                   AppStream
keycloak-httpd-client-install.noarch                 0.8-7.el8                                               AppStream
libmicrohttpd.i686                                   1:0.9.59-2.el8                                          BaseOS
libmicrohttpd.x86_64                                 1:0.9.59-2.el8                                          BaseOS
python3-keycloak-httpd-client-install.noarch         0.8-7.el8                                               AppStream
[root@CENTOS8 ~]#

ここで、httpdに関連するパッケージは以下となります。

パッケージ 内容
httpd httpdの本体
httpd-tools httpdに関連するツール群
httpd-devel httpd開発ツール、モジュール等
httpd-filesystem Apache HTTPサーバーの基本的なディレクトリレイアウト
httpd-manual httpdのマニュアル

httpdhttpd-toolsは必須で、httpd-develはApacheと関連するソフトウェアを./configuremakemake installでインストールする際に必要だったります。

2. Apache(httpd)のインストール

ここではhttpdhttpd-toolshttpd-develhttpd-manualをインストールします。

以下のコマンドでインストールします。-yを付けて確認内容をすべてyesとします。
dnf install -y httpd httpd-tools httpd-devel httpd-manual

[root@CENTOS8 ~]# dnf install -y httpd httpd-tools httpd-devel httpd-manual
メタデータの期限切れの最終確認: 0:01:37 時間前の 2019年12月30日 17時12分32秒 に 実施しました。
依存関係が解決しました。
================================================================================
 パッケージ        アーキテクチャー
                          バージョン                            リポジトリ
                                                                          サイズ
================================================================================
Installing:
 httpd             x86_64 2.4.37-12.module_el8.0.0+185+5908b0db AppStream 1.7 M
 httpd-devel       x86_64 2.4.37-12.module_el8.0.0+185+5908b0db AppStream 216 k
 httpd-manual      noarch 2.4.37-12.module_el8.0.0+185+5908b0db AppStream 2.4 M
 httpd-tools       x86_64 2.4.37-12.module_el8.0.0+185+5908b0db AppStream 102 k
依存関係をインストール中:
 apr               x86_64 1.6.3-9.el8                           AppStream 125 k
 apr-devel         x86_64 1.6.3-9.el8                           AppStream 246 k
 apr-util          x86_64 1.6.1-6.el8                           AppStream 105 k
 apr-util-devel    x86_64 1.6.1-6.el8                           AppStream  86 k
 centos-logos-httpd
                   noarch 80.5-2.el8                            AppStream  24 k
 httpd-filesystem  noarch 2.4.37-12.module_el8.0.0+185+5908b0db AppStream  35 k
 libdb-devel       x86_64 5.3.28-36.el8                         AppStream  46 k
 mod_http2         x86_64 1.11.3-3.module_el8.0.0+185+5908b0db  AppStream 158 k
 cyrus-sasl        x86_64 2.1.27-0.3rc7.el8                     BaseOS     96 k
 cyrus-sasl-devel  x86_64 2.1.27-0.3rc7.el8                     BaseOS    127 k
 expat-devel       x86_64 2.2.5-3.el8                           BaseOS     55 k
 mailcap           noarch 2.1.48-3.el8                          BaseOS     39 k
 openldap-devel    x86_64 2.4.46-9.el8                          BaseOS    810 k
 perl-Carp         noarch 1.42-396.el8                          BaseOS     30 k
 perl-Errno        x86_64 1.28-416.el8                          BaseOS     76 k
 perl-Exporter     noarch 5.72-396.el8                          BaseOS     34 k
 perl-File-Path    noarch 2.15-2.el8                            BaseOS     38 k
 perl-IO           x86_64 1.38-416.el8                          BaseOS    141 k
 perl-PathTools    x86_64 3.74-1.el8                            BaseOS     90 k
 perl-Scalar-List-Utils
                   x86_64 3:1.49-2.el8                          BaseOS     68 k
 perl-Socket       x86_64 4:2.027-2.el8                         BaseOS     59 k
 perl-Text-Tabs+Wrap
                   noarch 2013.0523-395.el8                     BaseOS     24 k
 perl-Unicode-Normalize
                   x86_64 1.25-396.el8                          BaseOS     82 k
 perl-constant     noarch 1.33-396.el8                          BaseOS     25 k
 perl-interpreter  x86_64 4:5.26.3-416.el8                      BaseOS    6.3 M
 perl-libs         x86_64 4:5.26.3-416.el8                      BaseOS    1.6 M
 perl-macros       x86_64 4:5.26.3-416.el8                      BaseOS     72 k
 perl-parent       noarch 1:0.237-1.el8                         BaseOS     20 k
 perl-threads      x86_64 1:2.21-2.el8                          BaseOS     61 k
 perl-threads-shared
                   x86_64 1.58-2.el8                            BaseOS     48 k
弱い依存関係をインストール中:
 apr-util-bdb      x86_64 1.6.1-6.el8                           AppStream  25 k
 apr-util-openssl  x86_64 1.6.1-6.el8                           AppStream  27 k
Enabling module streams:
 httpd                    2.4

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

ダウンロードサイズの合計: 15 M
インストール済みのサイズ: 41 M
パッケージのダウンロード中です:
(1/36): apr-util-1.6.1-6.el8.x86_64.rpm          65 kB/s | 105 kB     00:01
(2/36): apr-1.6.3-9.el8.x86_64.rpm               74 kB/s | 125 kB     00:01
(3/36): apr-util-bdb-1.6.1-6.el8.x86_64.rpm     113 kB/s |  25 kB     00:00
(4/36): apr-devel-1.6.3-9.el8.x86_64.rpm        118 kB/s | 246 kB     00:02
(5/36): centos-logos-httpd-80.5-2.el8.noarch.rp 237 kB/s |  24 kB     00:00
(6/36): apr-util-devel-1.6.1-6.el8.x86_64.rpm   176 kB/s |  86 kB     00:00
(7/36): apr-util-openssl-1.6.1-6.el8.x86_64.rpm  45 kB/s |  27 kB     00:00
(8/36): httpd-filesystem-2.4.37-12.module_el8.0 154 kB/s |  35 kB     00:00
(9/36): httpd-devel-2.4.37-12.module_el8.0.0+18 159 kB/s | 216 kB     00:01
(10/36): httpd-tools-2.4.37-12.module_el8.0.0+1 183 kB/s | 102 kB     00:00
(11/36): libdb-devel-5.3.28-36.el8.x86_64.rpm   136 kB/s |  46 kB     00:00
(12/36): mod_http2-1.11.3-3.module_el8.0.0+185+ 170 kB/s | 158 kB     00:00
(13/36): cyrus-sasl-2.1.27-0.3rc7.el8.x86_64.rp 137 kB/s |  96 kB     00:00
(14/36): cyrus-sasl-devel-2.1.27-0.3rc7.el8.x86 191 kB/s | 127 kB     00:00
(15/36): expat-devel-2.2.5-3.el8.x86_64.rpm     133 kB/s |  55 kB     00:00
(16/36): mailcap-2.1.48-3.el8.noarch.rpm        163 kB/s |  39 kB     00:00
(17/36): httpd-2.4.37-12.module_el8.0.0+185+590 203 kB/s | 1.7 MB     00:08
(18/36): perl-Carp-1.42-396.el8.noarch.rpm      112 kB/s |  30 kB     00:00
(19/36): perl-Errno-1.28-416.el8.x86_64.rpm     208 kB/s |  76 kB     00:00
(20/36): perl-Exporter-5.72-396.el8.noarch.rpm  171 kB/s |  34 kB     00:00
(21/36): perl-File-Path-2.15-2.el8.noarch.rpm   179 kB/s |  38 kB     00:00
(22/36): openldap-devel-2.4.46-9.el8.x86_64.rpm 174 kB/s | 810 kB     00:04
(23/36): perl-IO-1.38-416.el8.x86_64.rpm        176 kB/s | 141 kB     00:00
(24/36): perl-PathTools-3.74-1.el8.x86_64.rpm   138 kB/s |  90 kB     00:00
(25/36): perl-Socket-2.027-2.el8.x86_64.rpm     170 kB/s |  59 kB     00:00
(26/36): perl-Text-Tabs+Wrap-2013.0523-395.el8. 132 kB/s |  24 kB     00:00
(27/36): perl-Scalar-List-Utils-1.49-2.el8.x86_  84 kB/s |  68 kB     00:00
(28/36): perl-constant-1.33-396.el8.noarch.rpm   81 kB/s |  25 kB     00:00
(29/36): httpd-manual-2.4.37-12.module_el8.0.0+ 221 kB/s | 2.4 MB     00:10
(30/36): perl-Unicode-Normalize-1.25-396.el8.x8 187 kB/s |  82 kB     00:00
(31/36): perl-macros-5.26.3-416.el8.x86_64.rpm  123 kB/s |  72 kB     00:00
(32/36): perl-parent-0.237-1.el8.noarch.rpm      80 kB/s |  20 kB     00:00
(33/36): perl-threads-2.21-2.el8.x86_64.rpm      93 kB/s |  61 kB     00:00
(34/36): perl-threads-shared-1.58-2.el8.x86_64. 103 kB/s |  48 kB     00:00
(35/36): perl-libs-5.26.3-416.el8.x86_64.rpm    426 kB/s | 1.6 MB     00:03
(36/36): perl-interpreter-5.26.3-416.el8.x86_64 442 kB/s | 6.3 MB     00:14
--------------------------------------------------------------------------------
合計                                            494 kB/s |  15 MB     00:31
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
  準備             :                                                        1/1
  Installing       : perl-Exporter-5.72-396.el8.noarch                     1/36
  Installing       : perl-libs-4:5.26.3-416.el8.x86_64                     2/36
  Installing       : perl-Carp-1.42-396.el8.noarch                         3/36
  Installing       : apr-1.6.3-9.el8.x86_64                                4/36
  scriptletの実行中: apr-1.6.3-9.el8.x86_64                                4/36
  Installing       : apr-util-bdb-1.6.1-6.el8.x86_64                       5/36
  Installing       : apr-util-openssl-1.6.1-6.el8.x86_64                   6/36
  Installing       : apr-util-1.6.1-6.el8.x86_64                           7/36
  scriptletの実行中: apr-util-1.6.1-6.el8.x86_64                           7/36
  Installing       : perl-Scalar-List-Utils-3:1.49-2.el8.x86_64            8/36
  Installing       : apr-devel-1.6.3-9.el8.x86_64                          9/36
  Installing       : httpd-tools-2.4.37-12.module_el8.0.0+185+5908b0db.   10/36
  Installing       : perl-macros-4:5.26.3-416.el8.x86_64                  11/36
  Installing       : perl-parent-1:0.237-1.el8.noarch                     12/36
  Installing       : perl-Errno-1.28-416.el8.x86_64                       13/36
  Installing       : perl-Socket-4:2.027-2.el8.x86_64                     14/36
  Installing       : perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch         15/36
  Installing       : perl-Unicode-Normalize-1.25-396.el8.x86_64           16/36
  Installing       : perl-File-Path-2.15-2.el8.noarch                     17/36
  Installing       : perl-IO-1.38-416.el8.x86_64                          18/36
  Installing       : perl-PathTools-3.74-1.el8.x86_64                     19/36
  Installing       : perl-constant-1.33-396.el8.noarch                    20/36
  Installing       : perl-threads-1:2.21-2.el8.x86_64                     21/36
  Installing       : perl-threads-shared-1.58-2.el8.x86_64                22/36
  Installing       : perl-interpreter-4:5.26.3-416.el8.x86_64             23/36
  Installing       : mailcap-2.1.48-3.el8.noarch                          24/36
  Installing       : expat-devel-2.2.5-3.el8.x86_64                       25/36
  scriptletの実行中: cyrus-sasl-2.1.27-0.3rc7.el8.x86_64                  26/36
  Installing       : cyrus-sasl-2.1.27-0.3rc7.el8.x86_64                  26/36
  scriptletの実行中: cyrus-sasl-2.1.27-0.3rc7.el8.x86_64                  26/36
  Installing       : cyrus-sasl-devel-2.1.27-0.3rc7.el8.x86_64            27/36
  Installing       : openldap-devel-2.4.46-9.el8.x86_64                   28/36
  Installing       : libdb-devel-5.3.28-36.el8.x86_64                     29/36
  Installing       : apr-util-devel-1.6.1-6.el8.x86_64                    30/36
  scriptletの実行中: httpd-filesystem-2.4.37-12.module_el8.0.0+185+5908   31/36
  Installing       : httpd-filesystem-2.4.37-12.module_el8.0.0+185+5908   31/36
  Installing       : centos-logos-httpd-80.5-2.el8.noarch                 32/36
  Installing       : mod_http2-1.11.3-3.module_el8.0.0+185+5908b0db.x86   33/36
  Installing       : httpd-2.4.37-12.module_el8.0.0+185+5908b0db.x86_64   34/36
  scriptletの実行中: httpd-2.4.37-12.module_el8.0.0+185+5908b0db.x86_64   34/36
  Installing       : httpd-devel-2.4.37-12.module_el8.0.0+185+5908b0db.   35/36
  Installing       : httpd-manual-2.4.37-12.module_el8.0.0+185+5908b0db   36/36
  scriptletの実行中: httpd-2.4.37-12.module_el8.0.0+185+5908b0db.x86_64   36/36
  scriptletの実行中: httpd-manual-2.4.37-12.module_el8.0.0+185+5908b0db   36/36
  検証             : apr-1.6.3-9.el8.x86_64                                1/36
  検証             : apr-devel-1.6.3-9.el8.x86_64                          2/36
  検証             : apr-util-1.6.1-6.el8.x86_64                           3/36
  検証             : apr-util-bdb-1.6.1-6.el8.x86_64                       4/36
  検証             : apr-util-devel-1.6.1-6.el8.x86_64                     5/36
  検証             : apr-util-openssl-1.6.1-6.el8.x86_64                   6/36
  検証             : centos-logos-httpd-80.5-2.el8.noarch                  7/36
  検証             : httpd-2.4.37-12.module_el8.0.0+185+5908b0db.x86_64    8/36
  検証             : httpd-devel-2.4.37-12.module_el8.0.0+185+5908b0db.    9/36
  検証             : httpd-filesystem-2.4.37-12.module_el8.0.0+185+5908   10/36
  検証             : httpd-manual-2.4.37-12.module_el8.0.0+185+5908b0db   11/36
  検証             : httpd-tools-2.4.37-12.module_el8.0.0+185+5908b0db.   12/36
  検証             : libdb-devel-5.3.28-36.el8.x86_64                     13/36
  検証             : mod_http2-1.11.3-3.module_el8.0.0+185+5908b0db.x86   14/36
  検証             : cyrus-sasl-2.1.27-0.3rc7.el8.x86_64                  15/36
  検証             : cyrus-sasl-devel-2.1.27-0.3rc7.el8.x86_64            16/36
  検証             : expat-devel-2.2.5-3.el8.x86_64                       17/36
  検証             : mailcap-2.1.48-3.el8.noarch                          18/36
  検証             : openldap-devel-2.4.46-9.el8.x86_64                   19/36
  検証             : perl-Carp-1.42-396.el8.noarch                        20/36
  検証             : perl-Errno-1.28-416.el8.x86_64                       21/36
  検証             : perl-Exporter-5.72-396.el8.noarch                    22/36
  検証             : perl-File-Path-2.15-2.el8.noarch                     23/36
  検証             : perl-IO-1.38-416.el8.x86_64                          24/36
  検証             : perl-PathTools-3.74-1.el8.x86_64                     25/36
  検証             : perl-Scalar-List-Utils-3:1.49-2.el8.x86_64           26/36
  検証             : perl-Socket-4:2.027-2.el8.x86_64                     27/36
  検証             : perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch         28/36
  検証             : perl-Unicode-Normalize-1.25-396.el8.x86_64           29/36
  検証             : perl-constant-1.33-396.el8.noarch                    30/36
  検証             : perl-interpreter-4:5.26.3-416.el8.x86_64             31/36
  検証             : perl-libs-4:5.26.3-416.el8.x86_64                    32/36
  検証             : perl-macros-4:5.26.3-416.el8.x86_64                  33/36
  検証             : perl-parent-1:0.237-1.el8.noarch                     34/36
  検証             : perl-threads-1:2.21-2.el8.x86_64                     35/36
  検証             : perl-threads-shared-1.58-2.el8.x86_64                36/36

インストール済み:
  httpd-2.4.37-12.module_el8.0.0+185+5908b0db.x86_64
  httpd-devel-2.4.37-12.module_el8.0.0+185+5908b0db.x86_64
  httpd-manual-2.4.37-12.module_el8.0.0+185+5908b0db.noarch
  httpd-tools-2.4.37-12.module_el8.0.0+185+5908b0db.x86_64
  apr-util-bdb-1.6.1-6.el8.x86_64
  apr-util-openssl-1.6.1-6.el8.x86_64
  apr-1.6.3-9.el8.x86_64
  apr-devel-1.6.3-9.el8.x86_64
  apr-util-1.6.1-6.el8.x86_64
  apr-util-devel-1.6.1-6.el8.x86_64
  centos-logos-httpd-80.5-2.el8.noarch
  httpd-filesystem-2.4.37-12.module_el8.0.0+185+5908b0db.noarch
  libdb-devel-5.3.28-36.el8.x86_64
  mod_http2-1.11.3-3.module_el8.0.0+185+5908b0db.x86_64
  cyrus-sasl-2.1.27-0.3rc7.el8.x86_64
  cyrus-sasl-devel-2.1.27-0.3rc7.el8.x86_64
  expat-devel-2.2.5-3.el8.x86_64
  mailcap-2.1.48-3.el8.noarch
  openldap-devel-2.4.46-9.el8.x86_64
  perl-Carp-1.42-396.el8.noarch
  perl-Errno-1.28-416.el8.x86_64
  perl-Exporter-5.72-396.el8.noarch
  perl-File-Path-2.15-2.el8.noarch
  perl-IO-1.38-416.el8.x86_64
  perl-PathTools-3.74-1.el8.x86_64
  perl-Scalar-List-Utils-3:1.49-2.el8.x86_64
  perl-Socket-4:2.027-2.el8.x86_64
  perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch
  perl-Unicode-Normalize-1.25-396.el8.x86_64
  perl-constant-1.33-396.el8.noarch
  perl-interpreter-4:5.26.3-416.el8.x86_64
  perl-libs-4:5.26.3-416.el8.x86_64
  perl-macros-4:5.26.3-416.el8.x86_64
  perl-parent-1:0.237-1.el8.noarch
  perl-threads-1:2.21-2.el8.x86_64
  perl-threads-shared-1.58-2.el8.x86_64

完了しました!
[root@CENTOS8 ~]#

3. インストールの確認

以下のコマンドでインストールされていることを確認します。
dnf list --installed | grep httpd

[root@CENTOS8 ~]# dnf list --installed | grep httpd
centos-logos-httpd.noarch            80.5-2.el8                            @AppStream
httpd.x86_64                         2.4.37-12.module_el8.0.0+185+5908b0db @AppStream
httpd-devel.x86_64                   2.4.37-12.module_el8.0.0+185+5908b0db @AppStream
httpd-filesystem.noarch              2.4.37-12.module_el8.0.0+185+5908b0db @AppStream
httpd-manual.noarch                  2.4.37-12.module_el8.0.0+185+5908b0db @AppStream
httpd-tools.x86_64                   2.4.37-12.module_el8.0.0+185+5908b0db @AppStream
[root@CENTOS8 ~]#

以下のコマンドでインストールパスを確認します。
which httpd

[root@CENTOS8 ~]# which httpd
/usr/sbin/httpd
[root@CENTOS8 ~]#

4. 設定ファイルの確認

/etc/httpd/conf/httpd.confがApache(httpd)の設定ファイルとなります。
設定の詳細はマニュアルを参考に設定してください。

マニュアルは/usr/share/httpd/manualに格納されており、index.htmlを開くと参照できます。

公式ページのマニュアル(日本語版)は以下となります。
Apache HTTP サーバ バージョン 2.4 ドキュメント - Apache HTTP サーバ バージョン 2.4

ここでは以下の部分のみ変更しました。

/etc/httpd/conf/httpd.conf
- #ServerName www.example.com:80
+ ServerName CENTOS8

以下のコマンドでhttpd.confの文法チェックを行うことができます。
apachectl configtest

[root@CENTOS8 ~]# apachectl configtest
Syntax OK
[root@CENTOS8 ~]#

5. Apache(httpd)の起動

以下のコマンドでApache(httpd)を起動します。
systemctl start httpd

[root@CENTOS8 ~]# systemctl start httpd
[root@CENTOS8 ~]#

なお、httpdのUnit定義ファイル'httpd.service'は以下に配置されています。
/usr/lib/systemd/system/httpd.service

停止させる場合、以下のコマンドで停止させます。
systemctl stop httpd

6. CentOSのファイアウォールの設定

CentOSに外部から80番ポートへのアクセスを許可するよう設定します。

firewall-cmd --add-service=http --zone=public --permanent

[root@CENTOS8 ~]# firewall-cmd --add-service=http --zone=public --permanent
success
[root@CENTOS8 ~]#

なお、上記コマンドの--add-service=httpの部分のhttp.xmlは以下に定義されています。
http.xmlhttpが'tcp'プロトコルの`80'ポートであることが定義されています。

/usr/lib/firewalld/services/http.xml
<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>WWW (HTTP)</short>
  <description>HTTP is the protocol used to serve Web pages. If you plan to make your Web server publicly available, enable this option. This option is not required for viewing pages locally or developing Web pages.</description>
  <port protocol="tcp" port="80"/>
</service>

ファイアウォールの設定を反映させます。
firewall-cmd --reload

[root@CENTOS8 ~]# firewall-cmd --reload
success
[root@CENTOS8 ~]#

ファイアウォールの設定内容を確認します。
firewall-cmd --list-all

[root@CENTOS8 ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp0s3
  sources:
  services: cockpit dhcpv6-client http ssh
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

[root@CENTOS8 ~]#

serviceshttpが追加されていればOKです。

7. テスト用ページ作成

var/www/html配下にテストページを作成する。

/var/www/html/index.html
<!DOCTYPE html>
<html lang="ja">
<head>
<title>test</title>
</head>
<body>
<h1>test1</h1>
<h2>test2</h2>
<h3>test3</h3>
<h4>test4</h4>
</body>
</hrml>

8. 他のPCからブラウザで確認

他のPCのブラウザから以下のURLにアクセスします。

http://ホスト名(またはIPアドレス)/

以下のページ(7で作成したテストページ)が開くとOKです。
httpd02.png

以上

22
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
14