8. Apache HTTP Server のインストール

学校で勉強したことの復習として残します。 今回は ウェブサーバーを建てて、WordPressをインストールし、内部から閲覧できるようになるまでを目指します。

Apache HTTP Server 2.4 のインストール

rootユーザーで作業している前提で進めます。rootユーザーではなく一般ユーザーの方はコマンド su - でルートユーザーに変更します。*1

CentOS インストール後、まだ一回もソフトウェアアップデートをかけていなかったら先に #yum updateで今入ってるパッケージをすべて最新にしておいてください。

  1. Apache HTTP Server 2.4 のインストール (Yumの使い方(後で))
# yum install httpd
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.riken.jp
~(中略)~
依存性を解決しました

========================================================================================================================
 Package                     アーキテクチャー       バージョン                            リポジトリー             容量
========================================================================================================================
インストール中:
 httpd                       x86_64                 2.4.6-89.el7.centos                   updates                 2.7 M
依存性関連でのインストールをします:
 apr                         x86_64                 1.4.8-3.el7_4.1                       base                    103 k
 apr-util                    x86_64                 1.5.2-6.el7                           base                     92 k
 httpd-tools                 x86_64                 2.4.6-89.el7.centos                   updates                  90 k
 mailcap                     noarch                 2.1.41-2.el7                          base                     31 k

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

総ダウンロード容量: 3.0 M
インストール容量: 10 M
Is this ok [y/d/N]: y (←yes としてyキーを押す

Downloading packages:
(1/5): apr-1.4.8-3.el7_4.1.x86_64.rpm                                                            | 103 kB  00:00:00
(2/5): httpd-tools-2.4.6-89.el7.centos.x86_64.rpm                                                |  90 kB  00:00:00
~(中略)~
インストール:
  httpd.x86_64 0:2.4.6-89.el7.centos

依存性関連をインストールしました:
  apr.x86_64 0:1.4.8-3.el7_4.1        apr-util.x86_64 0:1.5.2-6.el7       httpd-tools.x86_64 0:2.4.6-89.el7.centos
  mailcap.noarch 0:2.1.41-2.el7

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

OKです。

httpデーモンを起動させます。起動・停止は systemctl コマンドで行います。(CentOS6 の Service コマンドも使えます)
最初は止まっています。

[root@localhost ~]# systemctl status httpdhttpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:httpd(8)
           man:apachectl(8)

起動させます。

[root@localhost ~]# systemctl start httpd

起動しました。

# systemctl status httpd
 httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since 月 2019-05-20 17:40:17 JST; 3s ago
~(中略)~
 5月 20 17:40:17 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

常駐させます(再起動しても自動的に立ち上がる)

[root@localhost ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

常駐しました。

# 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 月 2019-05-20 17:40:17 JST; 5min ago
~(中略)~
 5月 20 17:40:17 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

ファイヤーウォールを開ける。

初期設定によってはファイヤーウォールが閉じている。その場合下記のようにエラーが表示され接続できない。

ファイヤーウォールの確認。今回は取り合えず public ゾーンに httpを追加します。

# firewall-cmd --list-all --zone=public
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens192
  sources:
  services: ssh dhcpv6-client
  ports:
~(後略)~
# firewall-cmd --zone=public --add-service=http --permanent
(zone=public に httpサービスを --permanent 永続的に追加。permanentでない場合は再起動等で元の設定に戻る)
success
[root@localhost ~]# firewall-cmd --reload (永続的に追加する場合、設定を読み込ませるにはリロードが必要)
success
[root@localhost ~]# firewall-cmd --list-all --zone=public(再確認)
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens192
  sources:
  services: ssh dhcpv6-client http ←(http が追加されてる)
  ports:
  protocols:
~(後略)~

ブラウザを開き http://localhost/ を見る。Testing 1 2 3 ... と出ていれば Apache がちゃんと動いている。

f:id:hirose-test:20180731231634j:plain

[root@localhost ~]# cd /var/www/html/ で html ディレクトリに移動した後で
# vi index.html としてテストページを作ります。 ( vi:linuxについてるテキストエディタ、には「コマンドモード」と「編集モード」があります。開始時は「コマンドモード」であり、キーボードの「i」を押すと編集モードに入り文字入力ができます。編集モードの時に「Esc」を押すとコマンドモードに戻ります。コマンドモードで「:wq」と入力しEnter すると保存して閉じます。)

viの使い方/基本操作

<!doctype html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>タイトルだよ</title>
</head>
<body>
ほげほげ
</body>
</html>

f:id:hirose-test:20180717235923j:plain

OKです。またスナップショットを撮っておきましょう。

f:id:hirose-test:20180719224129j:plain

9. php7.1のインストール

*1:なんでもできるルートユーザーで作業すると操作ミスが致命傷になるので、基本は一般ユーザーでいた方が安全なのですが、今回は練習ですので

/* -----codeの行番号----- */