AlmaLinux WEBサーバーapacheをインストールする

AlmaLinux WEBサーバーapacheをインストールする

AlmaLinuxにWEBサーバーであるApache httpd をインストールするまでの手順を記述してます。

環境

  • OS  AlmaLinux 8.3

インストール

dnfで、httpd をインストールします。

sudo dnf -y install httpd

バージョンを確認してみます。

httpd -v

<出力結果>
Server version: Apache/2.4.37 (AlmaLinux)
Server built:   Apr 20 2021 08:39:16

apache起動

インストールが終わったので、起動します。

sudo systemctl start httpd

自動起動は、enableを実行します。

sudo systemctl enable httpd

–now オプションをつけると「 enable (自動起動)」と「 start (起動)」を同時にできます。

sudo systemctl enable --now httpd

停止は、stopで可能です。

sudo systemctl stop httpd

状態は、statusで確認することが可能です。

systemctl status httpd

<出力結果>
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/httpd.service.d
           └─php-fpm.conf
   Active: active (running) since Sun 2021-05-02 15:16:19 JST; 9s ago
     Docs: man:httpd.service(8)
 Main PID: 327960 (httpd)
   Status: "Running, listening on: port 80"
    Tasks: 213 (limit: 16417)
   Memory: 20.2M
   CGroup: /system.slice/httpd.service
           ├─327960 /usr/sbin/httpd -DFOREGROUND
           ├─327966 /usr/sbin/httpd -DFOREGROUND
           ├─327967 /usr/sbin/httpd -DFOREGROUND
           ├─327968 /usr/sbin/httpd -DFOREGROUND
           └─327969 /usr/sbin/httpd -DFOREGROUND

 5月 02 15:16:18 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
 5月 02 15:16:19 localhost.localdomain httpd[327960]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain>
 5月 02 15:16:19 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
 5月 02 15:16:19 localhost.localdomain httpd[327960]: Server configured, listening on: port 80

firewall設定

外部のマシンから接続できるように80ポートを許可しておきます。

sudo firewall-cmd --add-port=80/tcp --zone=public --permanent

<出力結果>
success

再起動すると設定が、反映されます。

sudo firewall-cmd --reload

<出力結果>
success

動作確認

http://プライベートIP or localhost:80にアクセスすると、以下の画面が表示されます。

apacheのドキュメントルートは「/var/www/html/」となります。

試しに、以下の内容で編集して表示してみます。

## ファイル作成
sudo nano /var/www/html/index.html

<編集内容>

<html>
<body>
hello world
</body>
</html>  

hello worldが表示されます。

apache設定

設定ファイルは、以下の場所に存在します。このファイルで、ドメインの適応やポートの変更などを行うことが可能です。

/etc/httpd/conf/httpd.conf

起動ポート

Listen 80

ドメインの設定

#ServerName www.example.com:80

DocumentRootの設定

DocumentRoot "/var/www/html"

設定変更を行ったら、反映させるには再起動が必要となります。

sudo systemctl restart httpd