VirtualBoxにいれたCentOS8にApacheをインストールしてみた。

今回はこちらのサイトを参考に、VirtualBoxにいれたCentOS8にApacheをインストールしてみました。この記事は実施内容の備忘録となります。
www.rem-system.com

1. 環境

2. httpdのインストール

まずはdnfコマンドを使用して下記4つのパッケージをインストールしていきます。

httpd.x86_64 httpd ウェブサーバー本体
httpd-devel.x86_64 httpd開発ツール、モジュールなど
httpd-manual.noarch httpdのマニュアル
httpd-tools.x86_64 httpdに関連するツール群

dnf -y install httpd httpd-tools httpd-devel httpd-manual

f:id:edasaka:20191213133136p:plain
dnf -y install httpd httpd-tools httpd-devel httpd-manual
f:id:edasaka:20191213133204p:plain
インストール完了

3. httpdの起動

インストールしたhttpdを下記コマンドで起動します。

systemctl start httpd

4. httpd自動起動の設定

サーバーを起動した際、自動的にhttpdも起動するよう下記コマンドを実施します。

systemctl enable httpd

5. firewallに80番ポートの設定

80番ポートにアクセスできるよう、下記コマンドを実施します。

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

f:id:edasaka:20191213134318p:plain
firewall-cmd --add-service=http --permanent

設定を反映するために、下記コマンドを実施します。

firewall-cmd --reload

f:id:edasaka:20191213134431p:plain
firewall-cmd --reload

6. httpd.confの編集

下記コマンドでhttpd.confを開き、編集していきます。

vi /etc/httpd/conf/httpd.conf
① ServerNameの設定

ServerNameのコメントアウトをはずし。名前を編集します。

f:id:edasaka:20191213140638p:plain
修正前
f:id:edasaka:20191213140840p:plain
修正後

② "/var/www/html"のOptionsの設定

OptiionsのIndexesを削除します。

f:id:edasaka:20191213141115p:plain
修正前
f:id:edasaka:20191213141219p:plain
修正後

7. httpd.confのテストと設定の反映

httpd.confの修正が完了したら、確認するコマンドがあるので確認していきます。
確認してOKでしたら、システムに反映します。

httpd -t
systemctl restart httpd

f:id:edasaka:20191213142213p:plain
テストと反映

8. 不要な設定ファイルのリネーム

不要な設定ファイルをリネームします。

mv autoindex.conf autoindex.conf.org
mv welcome.conf welcome.conf.org

9. テストページの確認

/var/www/htmlに下記index.htmlを作成し、サーバーのIPもしくはlocalhostにブラウザでアクセスすると。。テストページが表示できました!

<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Test Page
</div>
</body>
</html>

f:id:edasaka:20191213142646p:plain
テストページ

以上、VirtualBoxにいれたCentOS8にApacheをインストールしてみた。でした。