AlmaLinux8にApache+PHPをインストールする

AlmaLinux release 8.5 (Arctic Sphynx)
Apache 2.4.37
PHP 7.2.24

Apacheをインストールする。

# dnf install httpd

Apacheの設定ファイル内の「Indexes」を削除して、index.phpが存在しない場合のディレクトリ内の一覧表示機能を無効にする。

<Directory "/var/www/html">
    #Options Indexes FollowSymLinks
    Options FollowSymLinks

続けてApacheの設定ファイルにドメインごとにディレクトリ指定を行う設定を追記する。

#
# test.example.com Subdomain configuration
#
<VirtualHost *:80>
        ServerName test.example.com
        DocumentRoot /var/www/html/test/
        <Directory /var/www/html/test/>
                AllowOverride All
        </Directory>
</VirtualHost>

SELinuxのラベル付けを行うためのユーティリティをインストールする。

# dnf install policycoreutils-python-utils

/var/www/html/test/以下のファイルをhttpdから変更できるようSELinuxのラベルを付与する。

# semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/test(/.*)?"
# restorecon -RF /var/www/html/test/

httpdがネットワークに接続することを許可する。

# setsebool -P httpd_can_network_connect true

PHPと使用する拡張をインストールする。

# dnf install php
# dnf install php-mbstring
# dnf install php-json
# dnf install php-mysqlnd
# dnf install php-xml
# dnf install php-gd

8MB程度のファイルをアップロードするため、下記の箇所を設定変更する。

post_max_size = 10M
upload_max_filesize = 10M

WEBサイトからE-mailを送信するため、sendmailをインストールして有効化する。

# dnf install sendmail
# dnf install postfix
# systemctl enable --now postfix

httpdからE-mailを送信できるようSELinuxの設定を変更する。

# setsebool -P httpd_can_sendmail true

Apacheを起動して有効化する。

# systemctl enable --now httpd