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: