0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

CentOS7にApacheインストール

Posted at

Apache インストール

下記コマンドをroot権限で実行する

インストール
# yum -y install httpd

下記コマンドでインストールされた Apache のバージョンを確認することができます。

バージョン確認
# httpd -version
Server version: Apache/2.4.6 (CentOS)

Apache 起動

下記コマンドで起動します。

起動
# service httpd start

起動を確認します。
「Active: active (running)」となっていればオッケーです。

起動確認
# systemctl status httpd.service
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
   Active: active (running) since Mo 2021-08-09 13:29:12 CEST; 4s ago

Apache 停止

下記コマンドで停止します。

停止
# service httpd stop

Apache 再起動

下記コマンドで再起動します。

再起動
# service httpd restart

自動起動の設定

サーバを起動した際に自動的に Apache を起動したい場合は、以下の手順で設定します。
まずは現在の設定を確認します。

設定確認
# systemctl is-enabled httpd
disabled

下記のコマンドで自動起動を設定します。

自動起動有効
# systemctl enable httpd.service

設定されたことを確認します。

設定確認
# systemctl is-enabled httpd
enabled

自動起動を無効にする場合は下記コマンドを実行

自動起動無効
# systemctl disable httpd.service

firewalldのポート(80番)開放

CentOS 7 の初期状態では firewalld というファイアウォールが起動しており、http(80番ポート)が開放されていないため、開放する必要がある。
まずは下記コマンドで firewalld の起動状態を確認。active (running)となっている。

起動確認
# systemctl status firewalld
firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled)
   Active: active (running) since Di 2021-08-10 16:40:55 CEST; 26min ago

次に下記コマンドで firewalld の設定内容を確認する。
「services:」に「http」が存在しない。

設定確認
# firewall-cmd --list-all
public (default, active)
  interfaces: enp0s3 enp0s8 enp0s9
  sources:
  services: dhcpv6-client ssh
  ports:
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:

下記コマンドでhttp(80番ポート)を開放する。

ポート開放
# firewall-cmd --zone=public --add-service=http --permanent
success

firewalld の設定再読み込み。

再読み込み
# firewall-cmd --reload
success

再度、 firewalld の設定内容を確認する。
「services:」に「http」が追加されている。

設定確認
# firewall-cmd --list-all
public (default, active)
  interfaces: enp0s3 enp0s8 enp0s9
  sources:
  services: dhcpv6-client http ssh
  ports:
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?