Oracle Linux 9でWordPressサーバを立てる


Oracle Linux 9でwordpressサーバをたてる、という記事を2022年9月に書き始めたのですが、Oracle Linux 9用のEPELレポジトリにfail2banが含まれていなかっため、sshへの簡単な対策が行えないため書くのを中断していました。

2023年7月25日の更新でfail2banが収録されたようなので、改めて手順を作成してみます

準備1: Oracle Cloud用手順

準備1-1: IPv6アドレス割り当て:Oracle Cloudコンソール側

Oracle Cloudのコンソールを開いて、インスタンスにIPv6アドレスを割り当てます。

また、割り当てられたIPv6アドレスを確認します。

準備1-2: インスタンス側操作

Oracle Linux 9のイメージではIPv6が有効化されていたので、特に設定する必要はありませんでした。

準備2: 一般的な前準備

準備2-1: 日本時間にする

日本に住んでいる場合、日本時間表記の方が使いやすいので、OSも日本時間表示に設定する。

$ sudo timedatectl set-timezone Japan
$ 

準備2-2: パッケージを最新にアップデートする

現時点でインストール済みパッケージを最新にします。

Oracle Linux 9ではyum updateではなくdnf updateとなります。アップデート後は再起動します。(yumコマンドでも動きます)

$ sudo dnf update -y
<略>
$ sudo reboot

手順2-3:日本語Locale対応

ja_JP.UTF-8など日本語Localeで設定した際、「Failed to set locale, defaulting to C.UTF-8」というメッセージが出力される場合があります。

その場合は日本語Localeを追加インストールします。

$ sudo dnf install langpacks-ja glibc-langpack-ja
<略>
$

手順3: EPELレポジトリの追加

EPELレポジトリを使うので、使用できるようにします。

Oracle Linux 8と異なり、Oracle-Linux-9.2-2023.08.31-0 ではOracle CloudのOS管理下にレポジトリ管理が委託されていませんでした。

手順3-1:レポジトリの状態を確認

現状のレポジトリ設定状況を「sudo dnf repolist –all」を実行して確認します。

出力内に「This system is receiving updates from OSMS server.」という文字がなければこの手順で実行できます。

$ sudo dnf repolist --all
repo id                      repo name                                  status
ol9_MODRHCK                  Latest RHCK with fixes from Oracle for Ora disabled
ol9_RDMA                     Oracle Linux 9 (x86_64) RDMA               disabled
ol9_UEKR7                    Oracle Linux 9 UEK Release 7 (x86_64)      enabled
ol9_addons                   Oracle Linux 9 Addons (x86_64)             enabled
ol9_appstream                Oracle Linux 9 Application Stream Packages enabled
ol9_baseos_latest            Oracle Linux 9 BaseOS Latest (x86_64)      enabled
ol9_codeready_builder        Oracle Linux 9 CodeReady Builder (x86_64)  disabled
ol9_developer                Oracle Linux 9 Development Packages (x86_6 disabled
ol9_developer_EPEL           Oracle Linux 9 EPEL Packages for Developme disabled
ol9_developer_UEKR7          Developer Preview of UEK Release 7 (x86_64 disabled
ol9_developer_kvm_utils      Oracle Linux 9 KVM Utilities for Developme disabled
ol9_distro_builder           Oracle Linux 9 Distro Builder (x86_64) - ( disabled
ol9_ksplice                  Ksplice for Oracle Linux 9 (x86_64)        enabled
ol9_kvm_utils                Oracle Linux 9 KVM Utilities (x86_64)      disabled
ol9_oci_included             Oracle Linux 9 OCI Included Packages (x86_ enabled
ol9_u0_baseos_base           Oracle Linux 9 BaseOS GA (x86_64)          disabled
ol9_u1_baseos_base           Oracle Linux 9.1 BaseOS (x86_64)           disabled
ol9_u2_baseos_base           Oracle Linux 9.2 BaseOS (x86_64)           disabled
ol9_x86_64_userspace_ksplice Ksplice aware userspace packages for Oracl disabled
$

有効化するために「sudo dnf config-manager –set-enabled ol9_developer_EPEL」を実行します。

$ sudo dnf config-manager --set-enabled ol9_developer_EPEL
$ sudo dnf repolist --all
repo id                      repo name                                  status
ol9_MODRHCK                  Latest RHCK with fixes from Oracle for Ora disabled
ol9_RDMA                     Oracle Linux 9 (x86_64) RDMA               disabled
ol9_UEKR7                    Oracle Linux 9 UEK Release 7 (x86_64)      enabled
ol9_addons                   Oracle Linux 9 Addons (x86_64)             enabled
ol9_appstream                Oracle Linux 9 Application Stream Packages enabled
ol9_baseos_latest            Oracle Linux 9 BaseOS Latest (x86_64)      enabled
ol9_codeready_builder        Oracle Linux 9 CodeReady Builder (x86_64)  disabled
ol9_developer                Oracle Linux 9 Development Packages (x86_6 disabled
ol9_developer_EPEL           Oracle Linux 9 EPEL Packages for Developme enabled
ol9_developer_UEKR7          Developer Preview of UEK Release 7 (x86_64 disabled
ol9_developer_kvm_utils      Oracle Linux 9 KVM Utilities for Developme disabled
ol9_distro_builder           Oracle Linux 9 Distro Builder (x86_64) - ( disabled
ol9_ksplice                  Ksplice for Oracle Linux 9 (x86_64)        enabled
ol9_kvm_utils                Oracle Linux 9 KVM Utilities (x86_64)      disabled
ol9_oci_included             Oracle Linux 9 OCI Included Packages (x86_ enabled
ol9_u0_baseos_base           Oracle Linux 9 BaseOS GA (x86_64)          disabled
ol9_u1_baseos_base           Oracle Linux 9.1 BaseOS (x86_64)           disabled
ol9_u2_baseos_base           Oracle Linux 9.2 BaseOS (x86_64)           disabled
ol9_x86_64_userspace_ksplice Ksplice aware userspace packages for Oracl disabled
$

手順4: インターネット公開用設定

手順4-1: fail2ban導入

公開サーバは各種のアタックにさらされます。管理用sshポートにもやってきます。

多少なりとも軽減するためにEPELレポジトリ収録のfail2banを使用します。

$ sudo dnf install fail2ban -y
<略>
$

カスタム設定は/etc/fail2ban/jail.local に対して行います。

$ sudo vi /etc/fail2ban/jail.local
$ cat /etc/fail2ban/jail.local
[DEFAULT]
# 86400秒=24時間以内に5回不審なアクセスがあったら24時間BAN
bantime  = 86400
findtime  = 86400
maxretry = 5
# 259200秒=3日以内に5回不審なアクセスがあったら3日間BAN
#bantime  = 259200
#findtime  = 259200
#maxretry = 5
# 除外IP
ignoreip = 127.0.0.1 127.0.0.0/8 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16
[sshd]
enabled = true
banaction = firewallcmd-ipset
$

上記設定では24時間BANにしていますが、まぁ、3日BANでもかまわないとは思います。(本当に間違えた場合に困るのでほどほどにしておくとよい)

fail2banをOS起動時に実行する設定と、今すぐfail2banを起動するコマンドを実行します。

$ sudo systemctl enable fail2ban
$ sudo systemctl start fail2ban
$

以降、アタックがあると /var/log/fail2ban.log にログが出ます。

手順4-2: Webサーバ用ポート公開設定

この段階では、dhcpv6-clientとsshのみが許可されています。

Webサーバ公開用にhttp(ポート80)とhttps(ポート443)を追加します。

$ sudo firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens3
  sources:
  services: dhcpv6-client ssh
  ports:
  protocols:
  forward: yes
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
$
$ sudo firewall-cmd --permanent --add-service=http
success
$ sudo firewall-cmd --permanent --add-service=https
success
$ sudo firewall-cmd --reload
success
$ sudo firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens3
  sources:
  services: dhcpv6-client http https ssh
  ports:
  protocols:
  forward: yes
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
$

手順5: php 7.4追加

Oracle Linux 9環境では、moduleという形で複数バージョンのソフトウェアが提供されている場合があります。

phpに関してどのようなものがあるのかを「dnf module list | grep php」を実行して確認します。

$ dnf module list | grep php
php        8.1    common [d], devel, minimal            PHP scripting language  
$

Oracle Linux 9.2では php 8.1だけが提供されているようなので、phpとだけ指定してインストールします。

$ sudo dnf install php -y
Last metadata expiration check: 0:18:54 ago on Tue 12 Sep 2023 11:13:37 AM JST.
Dependencies resolved.
================================================================================
 Package             Arch    Version                   Repository          Size
================================================================================
Installing:
 php                 x86_64  8.0.27-1.el9_1            ol9_appstream       10 k
Installing dependencies:
 apr                 x86_64  1.7.0-11.el9              ol9_appstream      132 k
 apr-util            x86_64  1.6.1-20.el9_2.1          ol9_appstream       98 k
 apr-util-bdb        x86_64  1.6.1-20.el9_2.1          ol9_appstream       12 k
 httpd-core          x86_64  2.4.53-11.0.1.el9_2.5     ol9_appstream      1.8 M
 httpd-filesystem    noarch  2.4.53-11.0.1.el9_2.5     ol9_appstream       14 k
 httpd-tools         x86_64  2.4.53-11.0.1.el9_2.5     ol9_appstream       96 k
 nginx-filesystem    noarch  1:1.20.1-14.0.1.el9       ol9_appstream       11 k
 oracle-logos-httpd  noarch  90.2-1.0.2.el9            ol9_baseos_latest   37 k
 php-common          x86_64  8.0.27-1.el9_1            ol9_appstream      716 k
Installing weak dependencies:
 apr-util-openssl    x86_64  1.6.1-20.el9_2.1          ol9_appstream       14 k
 httpd               x86_64  2.4.53-11.0.1.el9_2.5     ol9_appstream       67 k
 mod_http2           x86_64  1.15.19-4.el9_2.4         ol9_appstream      157 k
 mod_lua             x86_64  2.4.53-11.0.1.el9_2.5     ol9_appstream       61 k
 php-cli             x86_64  8.0.27-1.el9_1            ol9_appstream      3.1 M
 php-fpm             x86_64  8.0.27-1.el9_1            ol9_appstream      1.6 M
 php-mbstring        x86_64  8.0.27-1.el9_1            ol9_appstream      470 k
 php-opcache         x86_64  8.0.27-1.el9_1            ol9_appstream      512 k
 php-pdo             x86_64  8.0.27-1.el9_1            ol9_appstream       90 k
 php-xml             x86_64  8.0.27-1.el9_1            ol9_appstream      144 k
Transaction Summary
================================================================================
Install  20 Packages
<略>
  php-pdo-8.0.27-1.el9_1.x86_64
  php-xml-8.0.27-1.el9_1.x86_64
Complete!
$

手順6: MySQL設定編

Oralce Linux 9.2ではMySQL 8.0.32 か mariadb 10.5.16が提供されています。

とりあえず、Oracle直営なのでMySQLを使っておきます。

$ sudo dnf install mysql-server -y
Last metadata expiration check: 0:23:36 ago on Tue 12 Sep 2023 11:13:37 AM JST.
Dependencies resolved.
================================================================================
 Package                      Arch     Version            Repository       Size
================================================================================
Installing:
 mysql-server                 x86_64   8.0.32-1.el9_2     ol9_appstream    17 M
Installing dependencies:
 mariadb-connector-c-config   noarch   3.2.6-1.el9_0      ol9_appstream   9.7 k
 mecab                        x86_64   0.996-3.el9.3      ol9_appstream   384 k
 mysql                        x86_64   8.0.32-1.el9_2     ol9_appstream   2.8 M
 mysql-common                 x86_64   8.0.32-1.el9_2     ol9_appstream   103 k
 mysql-errmsg                 x86_64   8.0.32-1.el9_2     ol9_appstream   513 k
 mysql-selinux                noarch   1.0.5-1.el9_0      ol9_appstream    35 k
 protobuf-lite                x86_64   3.14.0-13.el9      ol9_appstream   233 k
Transaction Summary
================================================================================
Install  8 Packages
<略>
Installed:
  mariadb-connector-c-config-3.2.6-1.el9_0.noarch
  mecab-0.996-3.el9.3.x86_64
  mysql-8.0.32-1.el9_2.x86_64
  mysql-common-8.0.32-1.el9_2.x86_64
  mysql-errmsg-8.0.32-1.el9_2.x86_64
  mysql-selinux-1.0.5-1.el9_0.noarch
  mysql-server-8.0.32-1.el9_2.x86_64
  protobuf-lite-3.14.0-13.el9.x86_64
Complete!
$

mysqldを自動起動する設定とします。

$ sudo systemctl enable mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
$

mysqldを起動します。

$ sudo systemctl start mysqld
$

WordPress用データベースを作成します。

MySQL 8におけるデータベースユーザ作成と権限の割り当てが従来の「grant all on DB名.* to wordpress@localhost identified by ‘パスワード’;」という一文から、「create user ~」と「grant ~」の2つに分かれている点に注意が必要です。

$ sudo mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.32 Source distribution
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database DB名 character set utf8;
Query OK, 1 row affected, 1 warning (0.01 sec)
mysql> create user wordpress@localhost  identified by 'パスワード';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on DB名.* to wordpress@localhost;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
$

手順7: Webサーバ設定

手順7-1: httpdインストール

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

Oracle Linux 9.2ではWebサーバとして Apache(httpd) 2.4.53 、nginx 1.20.1、nginx 1.22.1が使えるが、apacheを使う。

$ sudo dnf install httpd -y
Last metadata expiration check: 0:05:50 ago on Tue 12 Sep 2023 11:38:07 AM JST.
Package httpd-2.4.53-11.0.1.el9_2.5.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
$

って・・・よくみたらphpインストール時にインストール済みでした。

次で設定変更をするので、この段階ではhttpdを起動しません。

OS起動時に自動起動する設定だけを行います。

$ sudo systemctl enable httpd
$

手順7-2: dehydratedによるLet’s Encrypt導入

Let’s EncryptによるSSL証明書導入はcertbotを使うのが一般的ではあるのだが、python環境とあわせてパッケージサイズが大きいので、コンパクトでEPELにも収録されているdehydratedを使用する。

$ sudo dnf install dehydrated -y
Last metadata expiration check: 0:07:19 ago on Tue 12 Sep 2023 11:38:07 AM JST.
Dependencies resolved.
================================================================================
 Package         Arch        Version              Repository               Size
================================================================================
Installing:
 dehydrated      noarch      0.7.1-1.el9          ol9_developer_EPEL      154 k
Installing dependencies:
 s-nail          x86_64      14.9.22-6.el9        ol9_appstream           626 k
Transaction Summary
================================================================================
Install  2 Packages
<略>
Installed:
  dehydrated-0.7.1-1.el9.noarch           s-nail-14.9.22-6.el9.x86_64
Complete!
$

dehydratedによるSSL証明書取得処理には /var/www/dehydrated が使用されるためディレクトリを作成します。

$ sudo mkdir  /var/www/dehydrated
$

http://~/.well-known/acme-challenge でアクセスした時に上記ディレクトリが開くようApacheの設定を /etc/httpd/conf.d/dehydrated.conf として作成します。(sudo vi /etc/httpd/conf.d/dehydrated.conf )

$ sudo vi /etc/httpd/conf.d/dehydrated.conf
$ cat /etc/httpd/conf.d/dehydrated.conf
Alias /.well-known/acme-challenge /var/www/dehydrated
<Directory /var/www/dehydrated/>
</Directory>
$

httpdを起動します

$ sudo systemctl start httpd
$

SSL証明書を発行するホスト名を /etc/dehydrated/domains.txt に記載する。(sudo vi /etc/dehydrated/domains.txt)

1行に複数のホスト名を記載するとaliasになります。

$ sudo vi /etc/dehydrated/domains.txt
$ sudo cat /etc/dehydrated/domains.txt
ホスト1名.ドメイン名 ホスト2名.ドメイン名
$

登録操作を開始します。

$ sudo dehydrated --register
# INFO: Using main config file /etc/dehydrated/config
# INFO: Using additional config file /etc/dehydrated/conf.d/local.sh
To use dehydrated with this certificate authority you have to agree to their terms of service which you can find here: https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf
To accept these terms of service run "/bin/dehydrated --register --accept-terms".
$ sudo /bin/dehydrated --register --accept-terms
# INFO: Using main config file /etc/dehydrated/config
# INFO: Using additional config file /etc/dehydrated/conf.d/local.sh
+ Generating account key...
+ Registering account key with ACME server...
+ Fetching account URL...
+ Done!
$

初回のSSL証明書発行処理を実行します。

$ sudo dehydrated --cron
# INFO: Using main config file /etc/dehydrated/config
# INFO: Using additional config file /etc/dehydrated/conf.d/local.sh
 + Creating chain cache directory /etc/dehydrated/chains
Processing ホスト1名.ドメイン名 with alternative names: ホスト2名.ドメイン名
 + Creating new directory /etc/dehydrated/certs/ホスト1名.ドメイン名 ...
 + Signing domains...
 + Generating private key...
 + Generating signing request...
 + Requesting new certificate order from CA...
 + Received 2 authorizations URLs from the CA
 + Handling authorization for ホスト1名.ドメイン名
 + Handling authorization for ホスト2名.ドメイン名
 + 2 pending challenge(s)
 + Deploying challenge tokens...
 + Responding to challenge for ホスト1名.ドメイン名 authorization...
 + Challenge is valid!
 + Responding to challenge for ホスト2名.ドメイン名 authorization...
 + Challenge is valid!
 + Cleaning challenge tokens...
 + Requesting certificate...
 + Checking certificate...
 + Done!
 + Creating fullchain.pem...
 + Done!
 + Running automatic cleanup
$

手順7-3: WebサーバへのSSL証明書設定

まず、httpdにmod_sslを追加します。

$ sudo dnf install mod_ssl -y
Last metadata expiration check: 0:13:55 ago on Tue 12 Sep 2023 11:38:07 AM JST.
Dependencies resolved.
================================================================================
 Package      Arch        Version                      Repository          Size
================================================================================
Installing:
 mod_ssl      x86_64      1:2.4.53-11.0.1.el9_2.5      ol9_appstream      119 k
Transaction Summary
================================================================================
Install  1 Package
<略>
$

標準の /etc/httpd/conf.d/ssl.conf は使わず、Mozilla SSL Configuration Generatorベースの設定を /etc/httpd/conf.d/ssl-mozilla.conf として作成します。(なお、ssl.conf には”Listen 443 https”設定もあるので、そのままにしています)

$ sudo vi /etc/httpd/conf.d/ssl-mozilla.conf
$ cat /etc/httpd/conf.d/ssl-mozilla.conf
# generated 2023-09-12, Mozilla Guideline v5.7, Apache 2.4.53, OpenSSL 3.0.7, intermediate configuration
# https://ssl-config.mozilla.org/#server=apache&version=2.4.53&config=intermediate&openssl=3.0.7&guideline=5.7
# this configuration requires mod_ssl, mod_socache_shmcb, mod_rewrite, and mod_headers
<VirtualHost *:80>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/\.well\-known/acme\-challenge/
    RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>
<VirtualHost *:443>
    SSLEngine on
    # curl https://ssl-config.mozilla.org/ffdhe2048.txt >> /path/to/signed_cert_and_intermediate_certs_and_dhparams
    SSLCertificateFile      /etc/dehydrated/certs/<ホスト名>/cert.pem
    SSLCertificateKeyFile   /etc/dehydrated/certs/<ホスト名>/privkey.pem
    # enable HTTP/2, if available
    Protocols h2 http/1.1
    # HTTP Strict Transport Security (mod_headers is required) (63072000 seconds)
    Header always set Strict-Transport-Security "max-age=63072000"
</VirtualHost>
# intermediate configuration
SSLProtocol             all -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite          ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305
SSLHonorCipherOrder     off
SSLSessionTickets       off
SSLUseStapling On
SSLStaplingCache "shmcb:logs/ssl_stapling(32768)"
$

httpdを再起動します。

$ sudo systemctl restart httpd
$

手順8: WordPress導入

手順8-1: WordPressの基本インストール

WordPressのWebから最新版をダウンロードして、/var/www/html以下に展開します。
(日本語環境向けのlatest-ja.tar.gzファイルを使っていないのはWordpressプラグインが正常にインストールできるかを確認するためにWP Multibyte Patchを手動インストールする手順を入れているためです)

$ cd /var/www/html
$ ls
$ sudo curl -O https://wordpress.org/latest.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 22.3M  100 22.3M    0     0  17.6M      0  0:00:01  0:00:01 --:--:-- 17.6M
$ ls
latest.tar.gz
$ sudo tar xfz latest.tar.gz
$ ls -l
total 22904
-rw-r--r--. 1 root   root   23447259 Sep 12 11:57 latest.tar.gz
drwxr-xr-x. 5 nobody nobody     4096 Aug 29 23:14 wordpress
$ sudo rm latest.tar.gz
$

WordPressディレクトリの所有者をWebサービスのユーザである「apache」に変更します。

$ ps -ef|grep http
root       44914       1  0 11:56 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     44915   44914  0 11:56 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     44916   44914  0 11:56 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     44917   44914  0 11:56 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     44918   44914  0 11:56 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
opc        45353    7003  0 11:59 pts/0    00:00:00 grep --color=auto http
$ sudo chown -R apache:apache wordpress/
$ ls -l
total 4
drwxr-xr-x. 5 apache apache 4096 Aug 29 23:14 wordpress
$

/var/www/html/wordpress をDocumentRootとするように ssl-mozilla.conf に追加して、httpdを再起動します。

$ sudo vi /etc/httpd/conf.d/ssl-mozilla.conf
$ cat /etc/httpd/conf.d/ssl-mozilla.conf
# generated 2023-09-12, Mozilla Guideline v5.7, Apache 2.4.53, OpenSSL 3.0.7, intermediate configuration
# https://ssl-config.mozilla.org/#server=apache&version=2.4.53&config=intermediate&openssl=3.0.7&guideline=5.7
# this configuration requires mod_ssl, mod_socache_shmcb, mod_rewrite, and mod_headers
<VirtualHost *:80>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/\.well\-known/acme\-challenge/
    RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>
<VirtualHost *:443>
    DocumentRoot /var/www/html/wordpress
    SSLEngine on
    # curl https://ssl-config.mozilla.org/ffdhe2048.txt >> /path/to/signed_cert_and_intermediate_certs_and_dhparams
    SSLCertificateFile      /etc/dehydrated/certs/<ホスト名>/cert.pem
    SSLCertificateKeyFile   /etc/dehydrated/certs/<ホスト名>/privkey.pem
    # enable HTTP/2, if available
    Protocols h2 http/1.1
    # HTTP Strict Transport Security (mod_headers is required) (63072000 seconds)
    Header always set Strict-Transport-Security "max-age=63072000"
</VirtualHost>
# intermediate configuration
SSLProtocol             all -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite          ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305
SSLHonorCipherOrder     off
SSLSessionTickets       off
SSLUseStapling On
SSLStaplingCache "shmcb:logs/ssl_stapling(32768)"
$
$ sudo systemctl restart httpd
$

手順8-2: 「missing the MySQL extension」がでる場合の手順

いまの状態でブラウザからアクセスすると、下記の表示になります。

これはphpからMySQLにアクセスするためのパッケージがインストールされていないためなので、php-mysqlndを追加して、httpdを再起動します。

$ sudo dnf install php-mysqlnd -y
Last metadata expiration check: 0:25:26 ago on Tue 12 Sep 2023 11:38:07 AM JST.
Dependencies resolved.
================================================================================
 Package           Architecture Version               Repository           Size
================================================================================
Installing:
 php-mysqlnd       x86_64       8.0.27-1.el9_1        ol9_appstream       157 k
Transaction Summary
================================================================================
Install  1 Package
<略>
$ sudo systemctl restart httpd
$

WordPressの設定手順を進めると wp-config.php に書き込めない、と出ますので、「sudo vi /var/www/html/wordpress/wp-config.php」を実行し、指定された内容を記載します。

手順9: SELinux設定

手順9-1: httpdのネットワーク接続問題

一見するとここまででうまく動いているように見えます。

しかし、プラグインをインストールしようとするとエラーになります。

/var/log/audit/audit.logを確認すると下記のようなログが出ています。

type=AVC msg=audit(1622095859.957:2064): avc:  denied  { name_connect } for  pid=8908 comm="php-fpm" dest=443 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:http_port_t:s0 tclass=tcp_socket permissive=0
type=AVC msg=audit(1622095868.397:2065): avc:  denied  { name_connect } for  pid=8313 comm="php-fpm" dest=443 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:http_port_t:s0 tclass=tcp_socket permissive=0
type=AVC msg=audit(1622095868.401:2066): avc:  denied  { name_connect } for  pid=8313 comm="php-fpm" dest=80 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:http_port_t:s0 tclass=tcp_socket permissive=0

これはhttpd_can_network_connect という値で制御されている

現在の設定値を「sudo getsebool -a |grep httpd_can_network」で確認し、「sudo setsebool -P httpd_can_network_connect on」で有効にする

$ sudo getsebool -a |grep httpd_can_network
httpd_can_network_connect --> off
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> off
httpd_can_network_memcache --> off
httpd_can_network_relay --> off
$ sudo setsebool -P httpd_can_network_connect on
$ sudo getsebool -a |grep httpd_can_network
httpd_can_network_connect --> on
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> off
httpd_can_network_memcache --> off
httpd_can_network_relay --> off
$

この変更ではhttpdの再起動は不要。

手順9-2: php-fpmの書き込み権限問題

プラグインやテーマのインストールについては問題なくても、WordPressのアップデートが出来ない。

このときの/var/log/audit/audit.logは下記

type=AVC msg=audit(1694506911.363:1538): avc:  denied  { write } for  pid=51364 comm="php-fpm" name="wordpress" dev="dm-0" ino=34891933 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:httpd_sys_content_t:s0 tclass=dir permissive=0

こちらは/var/www/html/wordpress に対して httpdから書き込みが行えるような SELinuxのコンテキストをつけることで解決する。

「sudo chcon -R -t httpd_sys_script_rw_t /var/www/html/wordpress」

$ ls -lZ /var/www/html/
total 4
drwxr-xr-x. 5 apache apache unconfined_u:object_r:httpd_sys_content_t:s0 4096 Sep 12 13:14 wordpress
$ sudo chcon -R -t httpd_sys_script_rw_t /var/www/html/wordpress
$ ls -lZ /var/www/html/
total 4
drwxr-xr-x. 5 apache apache unconfined_u:object_r:httpd_sys_rw_content_t:s0 4096 Sep 12 13:14 wordpress
$

手順9-3:Wordpressプラグイン追加の動作確認

WordPressプラグインがインストールできる状態になっているかを確認するために「WP Multibyte Patch」をインストールします。

これをインストールするとWordpressの設定画面([Settings]-[General])に「Site language(サイトの言語)」が追加され、「日本語」表示に切り替えることができるようになります。

手順10: WordPressで取り扱えるファイルサイズの拡大

WordPressで取り扱えるファイルは標準状態だと2MBになっている。

WordPressのドキュメントのFile Upload Sizes を見ると、これはphpの設定ファイル /etc/php.ini による制限となっている。

Oracle Linux 9の標準設定では下記の値となっている。

<略>
post_max_size = 8M
<略>
upload_max_filesize = 2M
<略>

で・・・よくある手順だと軽率に /etc/php.ini を書き換えていますが、 /etc/php.d/ 以下にファイルを追加することで、そちらの設定項目を優先させることができる機能があるため、 /etc/php.d/90-wordpress.ini に変更したい2行だけを記載したファイルを作成します。

$ sudo vi /etc/php.d/90-wordpress.ini
$ cat /etc/php.d/90-wordpress.ini
post_max_size = 100M
upload_max_filesize = 100M
$

phpの設定変更を反映させるために「sudo systemctl restart php-fpm」を実行します。

$ sudo systemctl restart php-fpm
$

手順11: WordPressのSite Health Status対応

WordPressのサイトステータスを見てみると、いくつかパッケージを要求されている。

上から順に調査

Oracle Linux 8ではimagemagickのphpモジュールはなかったが、Oracle Linux 9だとあったので「sudo dnf install php-pecl-imagick」でインストール

$ sudo dnf install php-pecl-imagick
Last metadata expiration check: 1:22:23 ago on Tue 12 Sep 2023 11:38:07 AM JST.
Dependencies resolved.
================================================================================
 Package                        Arch   Version         Repository          Size
================================================================================
Installing:
 php-pecl-imagick               x86_64 3.7.0-1.el9     ol9_developer_EPEL 149 k
Installing dependencies:
 ImageMagick-libs               x86_64 6.9.12.93-1.el9 ol9_developer_EPEL 2.6 M
 LibRaw                         x86_64 0.20.2-5.el9    ol9_appstream      382 k
 ModemManager-glib              x86_64 1.20.2-1.el9    ol9_baseos_latest  334 k
 adobe-mappings-cmap            noarch 20171205-12.el9 ol9_appstream      2.0 M
 adobe-mappings-cmap-deprecated noarch 20171205-12.el9 ol9_appstream      129 k
 adobe-mappings-pdf             noarch 20180407-10.el9 ol9_appstream      686 k
 adwaita-cursor-theme           noarch 40.1.1-3.el9    ol9_appstream      686 k
 adwaita-icon-theme             noarch 40.1.1-3.el9    ol9_appstream       16 M
 alsa-lib                       x86_64 1.2.8-3.el9     ol9_appstream      586 k
 at-spi2-atk                    x86_64 2.38.0-4.el9    ol9_appstream       92 k
 at-spi2-core                   x86_64 2.40.3-1.el9    ol9_appstream      262 k
 atk                            x86_64 2.36.0-5.el9    ol9_appstream      378 k
 avahi-glib                     x86_64 0.8-12.el9_2.1  ol9_appstream       13 k
 bluez-libs                     x86_64 5.64-2.el9      ol9_baseos_latest   83 k
 bubblewrap                     x86_64 0.4.1-6.el9     ol9_baseos_latest   50 k
 colord-libs                    x86_64 1.4.5-4.el9     ol9_appstream      235 k
 cups-libs                      x86_64 1:2.3.3op2-16.el9_2.1
                                                       ol9_baseos_latest  264 k
 exempi                         x86_64 2.6.0-0.2.20211007gite23c213.el9
                                                       ol9_appstream      531 k
 exiv2-libs                     x86_64 0.27.5-2.el9    ol9_appstream      780 k
 fdk-aac-free                   x86_64 2.0.0-8.el9     ol9_appstream      325 k
 flac-libs                      x86_64 1.3.3-10.el9    ol9_appstream      226 k
 flatpak-selinux                noarch 1.12.7-2.el9    ol9_appstream       22 k
 flatpak-session-helper         x86_64 1.12.7-2.el9    ol9_appstream       80 k
 fuse                           x86_64 2.9.9-15.el9    ol9_baseos_latest   91 k
 gd                             x86_64 2.3.2-3.el9     ol9_appstream      132 k
 gdk-pixbuf2-modules            x86_64 2.42.6-3.el9    ol9_appstream       96 k
 geoclue2                       x86_64 2.6.0-7.el9     ol9_appstream      136 k
 giflib                         x86_64 5.2.1-9.el9     ol9_appstream       53 k
 google-droid-sans-fonts        noarch 20200215-11.el9.2
                                                       ol9_appstream      2.7 M
 graphene                       x86_64 1.10.6-2.el9    ol9_appstream       64 k
 graphviz                       x86_64 2.44.0-25.el9   ol9_appstream      3.4 M
 gsm                            x86_64 1.0.19-6.el9    ol9_appstream       39 k
 gstreamer1                     x86_64 1.18.4-4.el9    ol9_appstream      1.5 M
 gstreamer1-plugins-base        x86_64 1.18.4-5.el9    ol9_appstream      2.1 M
 gtk-update-icon-cache          x86_64 3.24.31-2.el9   ol9_appstream       34 k
 gtk2                           x86_64 2.24.33-8.el9   ol9_appstream      3.6 M
 gtk3                           x86_64 3.24.31-2.el9   ol9_appstream      5.0 M
 hicolor-icon-theme             noarch 0.17-13.el9     ol9_appstream       70 k
 imath                          x86_64 3.1.2-1.el9     ol9_appstream      102 k
 iso-codes                      noarch 4.6.0-3.el9     ol9_appstream      4.0 M
 jasper-libs                    x86_64 2.0.28-3.el9    ol9_appstream      151 k
 jbig2dec-libs                  x86_64 0.19-7.el9      ol9_appstream       77 k
 jbigkit-libs                   x86_64 2.1-23.el9      ol9_appstream       58 k
 lcms2                          x86_64 2.12-3.el9      ol9_appstream      167 k
 libICE                         x86_64 1.0.10-8.el9    ol9_appstream       71 k
 libSM                          x86_64 1.2.3-10.el9    ol9_appstream       42 k
 libX11-xcb                     x86_64 1.7.0-7.el9     ol9_appstream       12 k
 libXaw                         x86_64 1.0.13-19.el9   ol9_appstream      198 k
 libXcomposite                  x86_64 0.4.5-7.el9     ol9_appstream       29 k
 libXcursor                     x86_64 1.2.0-7.el9     ol9_appstream       35 k
 libXdamage                     x86_64 1.1.5-7.el9     ol9_appstream       27 k
 libXfixes                      x86_64 5.0.3-16.el9    ol9_appstream       20 k
 libXi                          x86_64 1.7.10-8.el9    ol9_appstream       40 k
 libXinerama                    x86_64 1.1.4-10.el9    ol9_appstream       15 k
 libXmu                         x86_64 1.1.3-8.el9     ol9_appstream       79 k
 libXpm                         x86_64 3.5.13-8.el9_1  ol9_appstream       62 k
 libXrandr                      x86_64 1.5.2-8.el9     ol9_appstream       28 k
 libXt                          x86_64 1.2.0-6.el9     ol9_appstream      180 k
 libXtst                        x86_64 1.2.3-16.el9    ol9_appstream       21 k
 libXv                          x86_64 1.0.11-16.el9   ol9_appstream       19 k
 libXxf86vm                     x86_64 1.1.4-18.el9    ol9_appstream       19 k
 libasyncns                     x86_64 0.8-22.el9      ol9_appstream       30 k
 libcanberra                    x86_64 0.30-26.el9     ol9_appstream      100 k
 libcanberra-gtk3               x86_64 0.30-26.el9     ol9_appstream       39 k
 libdrm                         x86_64 2.4.114-1.el9   ol9_appstream      165 k
 libepoxy                       x86_64 1.5.5-4.el9     ol9_appstream      246 k
 libexif                        x86_64 0.6.22-6.el9    ol9_appstream      462 k
 libfontenc                     x86_64 1.1.3-17.el9    ol9_appstream       31 k
 libgexiv2                      x86_64 0.12.3-1.el9    ol9_appstream       88 k
 libglvnd                       x86_64 1:1.3.4-1.el9   ol9_appstream      134 k
 libglvnd-egl                   x86_64 1:1.3.4-1.el9   ol9_appstream       35 k
 libglvnd-glx                   x86_64 1:1.3.4-1.el9   ol9_appstream      141 k
 libgs                          x86_64 9.54.0-9.el9    ol9_appstream      3.4 M
 libgsf                         x86_64 1.14.47-5.el9   ol9_appstream      302 k
 libgxps                        x86_64 0.3.2-3.el9     ol9_appstream       86 k
 libijs                         x86_64 0.35-15.el9     ol9_appstream       30 k
 libiptcdata                    x86_64 1.0.5-9.el9     ol9_appstream       73 k
 libldac                        x86_64 2.0.2.3-10.el9  ol9_appstream       41 k
 liblqr-1                       x86_64 0.4.2-19.el9    ol9_developer_EPEL  53 k
 libnotify                      x86_64 0.7.9-8.el9     ol9_appstream       50 k
 libogg                         x86_64 2:1.3.4-6.el9   ol9_appstream       38 k
 libosinfo                      x86_64 1.10.0-1.el9    ol9_appstream      345 k
 libpaper                       x86_64 1.1.28-4.el9    ol9_appstream       67 k
 libpciaccess                   x86_64 0.16-6.el9      ol9_baseos_latest   28 k
 libraqm                        x86_64 0.8.0-1.el9     ol9_developer_EPEL  19 k
 libsbc                         x86_64 1.4-9.el9       ol9_appstream       45 k
 libsndfile                     x86_64 1.0.31-7.el9    ol9_appstream      212 k
 libtheora                      x86_64 1:1.1.1-31.el9  ol9_appstream      168 k
 libtiff                        x86_64 4.4.0-8.el9_2   ol9_appstream      202 k
 libtool-ltdl                   x86_64 2.4.6-45.el9    ol9_appstream       36 k
 libtracker-sparql              x86_64 3.1.2-3.el9_1   ol9_appstream      354 k
 libvisual                      x86_64 1:0.4.0-34.el9  ol9_appstream      152 k
 libvorbis                      x86_64 1:1.3.7-5.el9   ol9_appstream      198 k
 libwayland-client              x86_64 1.21.0-1.el9    ol9_appstream       32 k
 libwayland-cursor              x86_64 1.21.0-1.el9    ol9_appstream       18 k
 libwayland-egl                 x86_64 1.21.0-1.el9    ol9_appstream       12 k
 libwayland-server              x86_64 1.21.0-1.el9    ol9_appstream       41 k
 libwebp                        x86_64 1.2.0-6.el9_1   ol9_appstream      284 k
 libwmf-lite                    x86_64 0.2.12-10.el9   ol9_appstream       77 k
 libxkbcommon                   x86_64 1.0.3-4.el9     ol9_appstream      133 k
 libxshmfence                   x86_64 1.3-10.el9      ol9_appstream       13 k
 low-memory-monitor             x86_64 2.1-4.el9       ol9_appstream       42 k
 mesa-libEGL                    x86_64 22.3.0-2.el9    ol9_appstream      123 k
 mesa-libGL                     x86_64 22.3.0-2.el9    ol9_appstream      168 k
 mesa-libgbm                    x86_64 22.3.0-2.el9    ol9_appstream       37 k
 mesa-libglapi                  x86_64 22.3.0-2.el9    ol9_appstream       49 k
 mesa-vulkan-drivers            x86_64 22.3.0-2.el9    ol9_appstream      7.4 M
 mkfontscale                    x86_64 1.2.1-3.el9     ol9_appstream       37 k
 openexr-libs                   x86_64 3.1.1-2.el9     ol9_appstream      1.1 M
 openjpeg2                      x86_64 2.4.0-7.el9     ol9_appstream      170 k
 opus                           x86_64 1.3.1-10.el9    ol9_appstream      200 k
 orc                            x86_64 0.4.31-6.el9    ol9_appstream      188 k
 osinfo-db                      noarch 20221130-1.0.2.el9
                                                       ol9_appstream      1.2 M
 osinfo-db-tools                x86_64 1.10.0-1.el9    ol9_appstream       96 k
 ostree-libs                    x86_64 2023.1-6.el9_2  ol9_appstream      441 k
 pipewire-libs                  x86_64 0.3.47-3.el9_2  ol9_appstream      1.7 M
 poppler                        x86_64 21.01.0-14.el9  ol9_appstream      1.1 M
 poppler-data                   noarch 0.4.9-9.el9     ol9_appstream      2.1 M
 poppler-glib                   x86_64 21.01.0-14.el9  ol9_appstream      152 k
 pulseaudio-libs                x86_64 15.0-2.el9      ol9_appstream      726 k
 pulseaudio-utils               x86_64 15.0-2.el9      ol9_appstream       82 k
 rtkit                          x86_64 0.11-28.el9     ol9_appstream       69 k
 sound-theme-freedesktop        noarch 0.8-17.el9      ol9_appstream      407 k
 totem-pl-parser                x86_64 3.26.6-2.el9    ol9_appstream      238 k
 tracker                        x86_64 3.1.2-3.el9_1   ol9_appstream      616 k
 upower                         x86_64 0.99.13-2.el9   ol9_appstream      188 k
 urw-base35-bookman-fonts       noarch 20200910-6.el9  ol9_appstream      861 k
 urw-base35-c059-fonts          noarch 20200910-6.el9  ol9_appstream      888 k
 urw-base35-d050000l-fonts      noarch 20200910-6.el9  ol9_appstream       81 k
 urw-base35-fonts               noarch 20200910-6.el9  ol9_appstream       11 k
 urw-base35-fonts-common        noarch 20200910-6.el9  ol9_appstream       22 k
 urw-base35-gothic-fonts        noarch 20200910-6.el9  ol9_appstream      657 k
 urw-base35-nimbus-mono-ps-fonts
                                noarch 20200910-6.el9  ol9_appstream      810 k
 urw-base35-nimbus-roman-fonts  noarch 20200910-6.el9  ol9_appstream      870 k
 urw-base35-nimbus-sans-fonts   noarch 20200910-6.el9  ol9_appstream      1.3 M
 urw-base35-p052-fonts          noarch 20200910-6.el9  ol9_appstream      987 k
 urw-base35-standard-symbols-ps-fonts
                                noarch 20200910-6.el9  ol9_appstream       42 k
 urw-base35-z003-fonts          noarch 20200910-6.el9  ol9_appstream      281 k
 vulkan-loader                  x86_64 1.3.239.0-1.el9 ol9_appstream      143 k
 webrtc-audio-processing        x86_64 0.3.1-8.el9     ol9_appstream      310 k
 wireplumber                    x86_64 0.4.8-1.0.1.el9 ol9_appstream      123 k
 wireplumber-libs               x86_64 0.4.8-1.0.1.el9 ol9_appstream      335 k
 xdg-dbus-proxy                 x86_64 0.1.3-1.el9     ol9_appstream       41 k
 xdg-desktop-portal             x86_64 1.12.4-1.el9    ol9_appstream      453 k
 xkeyboard-config               noarch 2.33-2.el9      ol9_appstream      1.1 M
 xorg-x11-fonts-ISO8859-1-100dpi
                                noarch 7.5-33.el9      ol9_appstream      1.2 M
Installing weak dependencies:
 dconf                          x86_64 0.40.0-6.el9    ol9_appstream      121 k
 exiv2                          x86_64 0.27.5-2.el9    ol9_appstream      1.0 M
 flatpak                        x86_64 1.12.7-2.el9    ol9_appstream      1.8 M
 libcanberra-gtk2               x86_64 0.30-26.el9     ol9_appstream       26 k
 p11-kit-server                 x86_64 0.24.1-2.el9    ol9_appstream      202 k
 pipewire                       x86_64 0.3.47-3.el9_2  ol9_appstream       49 k
 pipewire-alsa                  x86_64 0.3.47-3.el9_2  ol9_appstream       59 k
 pipewire-jack-audio-connection-kit
                                x86_64 0.3.47-3.el9_2  ol9_appstream      133 k
 pipewire-pulseaudio            x86_64 0.3.47-3.el9_2  ol9_appstream       24 k
 tracker-miners                 x86_64 3.1.2-3.el9     ol9_appstream      1.0 M
 xdg-desktop-portal-gtk         x86_64 1.12.0-3.el9    ol9_appstream      162 k
Transaction Summary
================================================================================
Install  158 Packages
<略>
$

インストール後にサイトヘルスステータスを確認するとgdも消えている

続いて「sudo dnf install php-pecl-zip php-intl」をインストール

$ sudo dnf install php-pecl-zip php-intl
Last metadata expiration check: 1:28:15 ago on Tue 12 Sep 2023 11:38:07 AM JST.
Dependencies resolved.
================================================================================
 Package            Architecture Version              Repository           Size
================================================================================
Installing:
 php-intl           x86_64       8.0.27-1.el9_1       ol9_appstream       150 k
 php-pecl-zip       x86_64       1.19.2-6.el9         ol9_appstream        78 k
Installing dependencies:
 libzip             x86_64       1.7.3-7.el9          ol9_appstream        63 k
Transaction Summary
================================================================================
Install  3 Packages
<略>
$

これで、サイトヘルスステータスのパッケージ関連のメッセージは消えた。

手順12: WordPressの.htaccess有効化

/var/www/html/wordpress/.htaccess が作成されているが、Oracle Linux 8のhttpd標準設定ではこれを読み込むようにはなっていない。

これが有効になっていないと、パーマリンク設定を「基本」から変えた場合に個別記事にアクセスできなくなる。

/etc/httpd/conf.d/wordpress.conf にファイルを作って設定する。

$ sudo vi /etc/httpd/conf.d/wordpress.conf
$ cat /etc/httpd/conf.d/wordpress.conf
<Directory /var/www/html/wordpress/>
 Allowoverride All
</Directory>
$ sudo systemctl restart httpd
$

手順13: OS自動更新の設定

メンテナンスがめんどくさくなって忘れる可能性があるので、Oracle Linux 8の自動更新設定を実施。

以前はyum-cronでしたが、現在は dnf-automatic に変わったので、パッケージをインストールします。

$ sudo dnf install dnf-automatic -y
Last metadata expiration check: 1:30:59 ago on Tue 12 Sep 2023 11:38:07 AM JST.
Dependencies resolved.
================================================================================
 Package          Arch      Version                  Repository            Size
================================================================================
Installing:
 dnf-automatic    noarch    4.14.0-5.0.1.el9_2       ol9_baseos_latest     53 k
Transaction Summary
================================================================================
Install  1 Package
<略>
$

/etc/dnf/automatic.conf 内の「apply_updates = no」を「apply_updates = yes」に変更

$ sudo vi /etc/dnf/automatic.conf
$ cat /etc/dnf/automatic.conf
[commands]
#  What kind of upgrade to perform:
# default                            = all available upgrades
# security                           = only the security upgrades
upgrade_type = default
random_sleep = 0
# Maximum time in seconds to wait until the system is on-line and able to
# connect to remote repositories.
network_online_timeout = 60
# To just receive updates use dnf-automatic-notifyonly.timer
# Whether updates should be downloaded when they are available, by
# dnf-automatic.timer. notifyonly.timer, download.timer and
# install.timer override this setting.
download_updates = yes
# Whether updates should be applied when they are available, by
# dnf-automatic.timer. notifyonly.timer, download.timer and
# install.timer override this setting.
apply_updates = yes
[emitters]
# Name to use for this system in messages that are emitted.  Default is the
# hostname.
# system_name = my-host
# How to send messages.  Valid options are stdio, email and motd.  If
# emit_via includes stdio, messages will be sent to stdout; this is useful
# to have cron send the messages.  If emit_via includes email, this
# program will send email itself according to the configured options.
# If emit_via includes motd, /etc/motd file will have the messages. if
# emit_via includes command_email, then messages will be send via a shell
# command compatible with sendmail.
# Default is email,stdio.
# If emit_via is None or left blank, no messages will be sent.
emit_via = stdio
[email]
# The address to send email messages from.
email_from = root@example.com
# List of addresses to send messages to.
email_to = root
# Name of the host to connect to to send email messages.
email_host = localhost
[command]
# The shell command to execute. This is a Python format string, as used in
# str.format(). The format function will pass a shell-quoted argument called
# `body`.
# command_format = "cat"
# The contents of stdin to pass to the command. It is a format string with the
# same arguments as `command_format`.
# stdin_format = "{body}"
[command_email]
# The shell command to use to send email. This is a Python format string,
# as used in str.format(). The format function will pass shell-quoted arguments
# called body, subject, email_from, email_to.
# command_format = "mail -Ssendwait -s {subject} -r {email_from} {email_to}"
# The contents of stdin to pass to the command. It is a format string with the
# same arguments as `command_format`.
# stdin_format = "{body}"
# The address to send email messages from.
email_from = root@example.com
# List of addresses to send messages to.
email_to = root
[base]
# This section overrides dnf.conf
# Use this to filter DNF core messages
debuglevel = 1
$

そしてdnf-automatic.timerを有効化し、開始します。

$ sudo systemctl enable dnf-automatic.timer
Created symlink /etc/systemd/system/timers.target.wants/dnf-automatic.timer → /usr/lib/systemd/system/dnf-automatic.timer.
$ sudo systemctl status dnf-automatic
○ dnf-automatic.service - dnf automatic
     Loaded: loaded (/usr/lib/systemd/system/dnf-automatic.service; static)
     Active: inactive (dead)
TriggeredBy: ○ dnf-automatic.timer
$ sudo systemctl start dnf-automatic.timer
$ sudo systemctl status dnf-automatic.timer
● dnf-automatic.timer - dnf-automatic timer
     Loaded: loaded (/usr/lib/systemd/system/dnf-automatic.timer; enabled; pres>
     Active: active (waiting) since Tue 2023-09-12 13:11:00 JST; 5s ago
      Until: Tue 2023-09-12 13:11:00 JST; 5s ago
    Trigger: Wed 2023-09-13 06:44:33 JST; 17h left
   Triggers: ● dnf-automatic.service
Sep 12 13:11:00 ホスト名 systemd[1]: Started dnf-automatic timer.
$

Firewall内のCentOSからhttps://mirror.centos.org/にアクセスできなかった件


FortigateによるFirewall内にあるCentOS9サーバから「dnf check-update」を実行してみたところ、失敗した。

[root@centos9 ~]# dnf update
サブスクリプション管理リポジトリーを更新しています。
コンシューマー識別子を読み込めません

このシステムは、エンタイトルメントサーバーに登録されていません。subscription-manager で登録できます。

CentOS Stream 9 - BaseOS                        0.0  B/s |   0  B     00:03
Errors during downloading metadata for repository 'baseos':
  - Curl error (60): SSL peer certificate or SSH remote key was not OK for https://mirrors.centos.org/metalink?repo=centos-baseos-9-stream&arch=x86_64&protocol=https,http [SSL certificate problem: self-signed certificate in certificate chain]
エラー: repo 'baseos' のメタデータのダウンロードに失敗しました : Cannot prepare internal mirrorlist: Curl error (60): SSL peer certificate or SSH remote key was not OK for https://mirrors.centos.org/metalink?repo=centos-baseos-9-stream&arch=x86_64&protocol=https,http [SSL certificate problem: self-signed certificate in certificate chain]
[root@centos9 ~]#

内容的には https://mirrors.centos.org/ へのアクセスでエラーになっていたので、curlコマンドで状況を確認してみることにした。

[root@centos9 ~]# curl -vvv https://mirrors.centos.org/publiclist/
*   Trying 13.125.120.8:443...
* Connected to mirrors.centos.org (13.125.120.8) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
*  CAfile: /etc/pki/tls/certs/ca-bundle.crt
* TLSv1.0 (OUT), TLS header, Certificate Status (22):
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS header, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS header, Finished (20):
* TLSv1.2 (IN), TLS header, Unknown (23):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.2 (IN), TLS header, Unknown (23):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (OUT), TLS header, Unknown (21):
* TLSv1.3 (OUT), TLS alert, unknown CA (560):
* SSL certificate problem: self-signed certificate in certificate chain
* Closing connection 0
curl: (60) SSL certificate problem: self-signed certificate in certificate chain
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
[root@centos9 ~]#

同じ環境にあるCentOS7サーバやOracle Linux8サーバでも同じ結果になった。

他の環境にあるCentOS7サーバで実行してみると下記のような感じになった。

-bash-4.2$ curl -vvv https://mirrors.centos.org/publiclist/
* About to connect() to mirrors.centos.org port 443 (#0)
*   Trying 2620:52:3:1:dead:beef:cafe:fed6...
* Connected to mirrors.centos.org (2620:52:3:1:dead:beef:cafe:fed6) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* SSL connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate:
*       subject: CN=mirrors.centos.org
*       start date: 10月 19 06:06:54 2021 GMT
*       expire date:  1月 17 06:06:53 2022 GMT
*       common name: mirrors.centos.org
*       issuer: CN=R3,O=Let's Encrypt,C=US
> GET /publiclist/ HTTP/1.1
> User-Agent: curl/7.29.0
> Host: mirrors.centos.org
> Accept: */*
>
< HTTP/1.1 302 Found
< Date: Fri, 12 Nov 2021 08:44:59 GMT
< Server: Apache
< X-Frame-Options: SAMEORIGIN
< X-Xss-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< Referrer-Policy: same-origin
< Location: https://admin.fedoraproject.org/mirrormanager/
< Content-Length: 299
< Content-Type: text/html; charset=iso-8859-1
<
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="https://admin.fedoraproject.org/mirrormanager/">here</a>.</p>
<hr>
<address>Apache Server at mirrors.centos.org Port 443</address>
</body></html>
* Connection #0 to host mirrors.centos.org left intact
-bash-4.2$

Let’s Encryptの証明書使ってるな、ということで、同じ環境にあるブラウザからアクセスしてみると、Fortigateによるhttps周りの動作の問題であることが判明

解決方法は「FortiGate環境で”This Connection is Invalid. SSL certificate expired.”を食らった」にあるやつと同じでした。

Oracle Linux 8でWordPressサーバを立てる


Oracle CloudのAlways Freeで作れるインスタンスにARMベースのインスタンスが追加された。

従来のCPU1個/メモリ1GBに対して、CPU1~4個/メモリ6GB~24GBと破格のスペックなので、Wordpressサーバでも移行してみるかな、と思って、「CentOS 7 / Oracle Linux 7でWordPressサーバを建てる」の手順でつくろうとしてみたところ、Oracle Linux 7 ARMではPHP Packages for Oracle Linuxが提供されていなかった。

Oracle Linux 8であれば標準状態でphp 7.4が利用できるようなので、Oracle Linux 8で作成する手順を策定した。

変更履歴

・Wordpress本体を更新しようとしたらできなかったので「手順8-2: php-fpmの書き込み権限問題」追加
・既存blogのデータをインポートしようとしたらファイルサイズオーバーだったので「手順9: WordPressで取り扱えるファイルサイズの拡大」追加
・存在を思い出したので「手順10: WordPressのSite Health Status対応」追加
・パーマリンク設定を変更したら動かなかったので「手順11: WordPressの.htaccess有効化」追加
・「手順12: OS自動更新の設定」追加
・日本語Localeに設定した場合の対応として「手順2-3:日本語Locale対応」追加
・2022/04/06にOracle-Linux-8.5-aarch64-2022.03.17-1を使って構築した時の状況を追加
・手順8が2つあったので番号を振り直した
・wordpressにWP Multibyte Patchをインストールする手順を書き忘れていたので追加

また、手順8以降でWordpressにアクセスすると「Service Unavailable」と表示される場合があります。その場合は、php-fpmのSELinuxポリシー設定問題であるため「Oracle Linux 8でphp 7.4.19-1にアップデート後からphp-fpmが起動しなくなった」の対処を行ってみてください。

準備1: Oracle Cloud用手順

準備1-1: IPv6アドレス割り当て:Oracle Cloudコンソール側

Oracle Cloudのコンソールを開いて、インスタンスにIPv6アドレスを割り当てます。

また、割り当てられたIPv6アドレスを確認します。

準備1-2: インスタンス側操作

2021年5月27日の段階ではOracle Cloud環境で提供されるOracle Linux 8でIPv6アドレスの自動割り当てが動作していませんでした。

Oracle-Linux-8.5-aarch64-2022.03.17-1(2022/04/06時点)やOracle-Linux-8.6-aarch64-2022.05.30-0(2022/07/01時点)でも同様でした。

このため、firewalldの設定でdhcpv6-clientが許可されていないために発生していましたので、許可します。

まず初期状態を確認

$ sudo firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp0s3
  sources:
  services: ssh
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
$

dhcpv6-clientの許可設定と設定読み込みと確認

$ sudo firewall-cmd --permanent --add-service=dhcpv6-client
success
$ sudo firewall-cmd --reload
success
$ sudo firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp0s3
  sources:
  services: dhcpv6-client ssh
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
$

準備2: 一般的な前準備

準備2-1: 日本時間にする

日本に住んでいる場合、日本時間表記の方が使いやすいので、OSも日本時間表示に設定する。

$ sudo timedatectl set-timezone Japan
$ 

準備2-2: パッケージを最新にアップデートする

現時点でインストール済みパッケージを最新にします。

Oracle Linux 8ではyum updateではなくdnf updateとなります。アップデート後は再起動します。(yumコマンドでも動きます)

$ sudo dnf update -y
<略>
$ sudo reboot

手順2-3:日本語Locale対応

ja_JP.UTF-8など日本語Localeで設定した際、「Failed to set locale, defaulting to C.UTF-8」というメッセージが出力される場合があります。

その場合は日本語Localeを追加インストールします。

$ sudo dnf install langpacks-ja glibc-langpack-ja
<略>
$

手順3: EPELレポジトリの追加

EPELレポジトリを使うので、使用できるようにします。

Oracle Cloud上のOracle Linux 8環境ではレポジトリパッケージのインストールはされているので、有効化を行います。(なお、/etc/yum.repo.d/のファイルを編集するのは時代遅れな操作です)

また、2021年11月以降のOracle Cloudでの新規インスタンスではOS管理が有効になっている関係で手順が変わっています。新規で作る場合は手順3-1bの方を参照してください。

手順3-1a:通常の手順

Oracle Cloud外の環境でOracle Linux 8をインストールしている場合や古めのOracle Cloudインスタンスの場合、こちらのOS側のコマンドで設定する手順を行います。

現状のレポジトリ設定状況を「sudo dnf repolist –all」を実行して確認します。

$ sudo dnf repolist --all
repo id                          repo name                              status
ol8_MySQL80                      MySQL 8.0 for Oracle Linux 8 (aarch64) enabled
ol8_MySQL80_connectors_community MySQL 8.0 Connectors Community for Ora enabled
ol8_MySQL80_tools_community      MySQL 8.0 Tools Community for Oracle L enabled
ol8_aarch64_userspace_ksplice    Ksplice aware userspace packages for O disabled
ol8_appstream                    Oracle Linux 8 Application Stream (aar enabled
ol8_baseos_latest                Oracle Linux 8 BaseOS Latest (aarch64) enabled
ol8_codeready_builder            Oracle Linux 8 CodeReady Builder (aarc disabled
ol8_developer                    Oracle Linux 8 Development Packages (a disabled
ol8_developer_EPEL               Oracle Linux 8 EPEL Packages for Devel disabled
ol8_developer_UEKR6              Developer Preview of UEK Release 6 (aa disabled
ol8_distro_builder               Oracle Linux 8 Distro Builder (aarch64 disabled
ol8_ksplice                      Ksplice for Oracle Linux 8 (aarch64)   enabled
ol8_oci_included                 Oracle Software for OCI users on Oracl enabled
ol8_u2_baseos_base               Oracle Linux 8.2 BaseOS (aarch64)      disabled
ol8_u3_baseos_base               Oracle Linux 8.3 BaseOS (aarch64)      disabled
ol8_u4_baseos_base               Oracle Linux 8.4 BaseOS (aarch64)      disabled
$ 

上記の場合、ol8_developer_EPELが登録されているもののdisabledになっています。

この場合は「sudo dnf config-manager –set-enabled ol8_developer_EPEL」を実行し、enabledに変更されたことを確認します。

$ sudo dnf config-manager --set-enabled ol8_developer_EPEL
$ sudo dnf repolist --all
repo id                          repo name                              status
ol8_MySQL80                      MySQL 8.0 for Oracle Linux 8 (aarch64) enabled
ol8_MySQL80_connectors_community MySQL 8.0 Connectors Community for Ora enabled
ol8_MySQL80_tools_community      MySQL 8.0 Tools Community for Oracle L enabled
ol8_aarch64_userspace_ksplice    Ksplice aware userspace packages for O disabled
ol8_appstream                    Oracle Linux 8 Application Stream (aar enabled
ol8_baseos_latest                Oracle Linux 8 BaseOS Latest (aarch64) enabled
ol8_codeready_builder            Oracle Linux 8 CodeReady Builder (aarc disabled
ol8_developer                    Oracle Linux 8 Development Packages (a disabled
ol8_developer_EPEL               Oracle Linux 8 EPEL Packages for Devel enabled
ol8_developer_UEKR6              Developer Preview of UEK Release 6 (aa disabled
ol8_distro_builder               Oracle Linux 8 Distro Builder (aarch64 disabled
ol8_ksplice                      Ksplice for Oracle Linux 8 (aarch64)   enabled
ol8_oci_included                 Oracle Software for OCI users on Oracl enabled
ol8_u2_baseos_base               Oracle Linux 8.2 BaseOS (aarch64)      disabled
ol8_u3_baseos_base               Oracle Linux 8.3 BaseOS (aarch64)      disabled
ol8_u4_baseos_base               Oracle Linux 8.4 BaseOS (aarch64)      disabled
$

手順3-1b:Oracle CloudのOS管理下にある場合の手順

2022年4月6日時点でOracle Cloud上で提供されているOracle-Linux-8.5-aarch64-2022.03.17-1では「sudo dnf repolist –all」の実行結果に変化があり、「This system is receiving updates from OSMS server.」と書かれた上で、だいぶ整理されたレポジトリのみが表示されます。

$ sudo dnf repolist --all
This system is receiving updates from OSMS server.
repo id                                  repo name                       status
ol8_addons-aarch64                       Oracle Linux 8 Add ons (aarch64 enabled
ol8_appstream-aarch64                    Oracle Linux 8 Application Stre enabled
ol8_baseos_latest-aarch64                Oracle Linux 8 BaseOS Latest (a enabled
ol8_ksplice-aarch64                      Ksplice for Oracle Linux 8 (aar enabled
ol8_mysql80-aarch64                      MySQL 8.0 for Oracle Linux 8 (a enabled
ol8_mysql80_connectors_community-aarch64 MySQL 8.0 Connectors for Oracle enabled
ol8_mysql80_tools_community-aarch64      MySQL 8.0 Tools Community for O enabled
ol8_oci_included-aarch64                 Oracle Software for OCI users o enabled
$

これはOracle Cloudの「OS管理(OS Managemnt System)」という機能との連携が始まり、Oracle CloudのWebコンソール からパッチ状態を見れるように変更になったためです。

レポジトリの設定変更は上記画面の「…」をクリックし「OS管理詳細の表示」を選択

[リソース]-[ソフトウェア・ソース]から「追加」を選択

「Oralce Linux 8 EPEL Packages for Development」を選択し「追加」

Web上で追加されたことを確認

次にコマンドに戻り「sudo dnf repolist –all」を実行するとEPELレポジトリがenabledとして増えていることが確認できます。

$ sudo dnf repolist --all
This system is receiving updates from OSMS server.
repo id                                  repo name                       status
ol8_addons-aarch64                       Oracle Linux 8 Add ons (aarch64 enabled
ol8_appstream-aarch64                    Oracle Linux 8 Application Stre enabled
ol8_baseos_latest-aarch64                Oracle Linux 8 BaseOS Latest (a enabled
ol8_developer_epel-aarch64               Oracle Linux 8 EPEL Packages fo enabled
ol8_ksplice-aarch64                      Ksplice for Oracle Linux 8 (aar enabled
ol8_mysql80-aarch64                      MySQL 8.0 for Oracle Linux 8 (a enabled
ol8_mysql80_connectors_community-aarch64 MySQL 8.0 Connectors for Oracle enabled
ol8_mysql80_tools_community-aarch64      MySQL 8.0 Tools Community for O enabled
ol8_oci_included-aarch64                 Oracle Software for OCI users o enabled

手順4: インターネット公開用設定

手順4-1: fail2ban導入

公開サーバは各種のアタックにさらされます。管理用sshポートにもやってきます。

多少なりとも軽減するためにEPELレポジトリ収録のfail2banを使用します。

$ sudo dnf install fail2ban -y
$ 

カスタム設定は/etc/fail2ban/jail.localに行います。

$ sudo vi /etc/fail2ban/jail.local
$ cat /etc/fail2ban/jail.local
[DEFAULT]
# 86400秒=24時間以内に5回不審なアクセスがあったら24時間BAN
bantime  = 86400
findtime  = 86400
maxretry = 5
# 259200秒=3日以内に5回不審なアクセスがあったら3日間BAN
#bantime  = 259200
#findtime  = 259200
#maxretry = 5

# 除外IP
ignoreip = 127.0.0.1 127.0.0.0/8 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16

[sshd]
enabled = true
banaction = firewallcmd-ipset
$ 

上記設定では24時間BANにしていますが、まぁ、3日BANでもかまわないとは思います。(本当に間違えた場合に困るのでほどほどにしておくとよい)

fail2banをOS起動時に実行する設定と、今すぐfail2banを起動するコマンドを実行します。

$ sudo systemctl enable fail2ban
$ sudo systemctl start fail2ban
$

以降、アタックがあると /var/log/fail2ban.log にログが出ます。

手順4-2: Webサーバ用ポート公開設定

この段階では、dhcpv6-clientとsshのみが許可されています。

Webサーバ公開用にhttp(ポート80)とhttps(ポート443)を追加します。

$ sudo firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp0s3
  sources:
  services: dhcpv6-client ssh
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
$
$ sudo firewall-cmd --permanent --add-service=http
success
$ sudo firewall-cmd --permanent --add-service=https
success
$ sudo firewall-cmd --reload
success
$ sudo firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp0s3
  sources:
  services: dhcpv6-client http https ssh
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
$

手順5: php 7.4追加

Oracle Linux 8環境では、moduleという形で複数バージョンのソフトウェアが提供されています。

phpに関してどのようなものがあるのかを「dnf module list | grep php」を実行して確認します。

$ sudo dnf module list | grep php
php                  7.2 [d]         common [d], devel, minimal               PHP scripting language                                                                                                                                                                                
php                  7.3             common [d], devel, minimal               PHP scripting language                                                                                                                                                                                
php                  7.4             common [d], devel, minimal               PHP scripting language                                                                                                                                                                                
$

php 7.2が標準選択で、他にphp 7.3とphp 7.4が選べることがわかります。
2022/07/01時点で提供されているOracle Linux 8.6では php 8.0も選択できるようになっています。

php7.4を指定してパッケージを追加します。

$ sudo dnf install @php:7.4 -y
Last metadata expiration check: 0:07:11 ago on Thu 27 May 2021 01:04:16 PM JST.
Dependencies resolved.
==========================================================================================================================================
 Package                     Architecture       Version                                                Repository                    Size
==========================================================================================================================================
Installing group/module packages:
 php-cli                     aarch64            7.4.6-4.module+el8.3.0+7685+72d70b58                   ol8_appstream                2.8 M
 php-common                  aarch64            7.4.6-4.module+el8.3.0+7685+72d70b58                   ol8_appstream                675 k
 php-fpm                     aarch64            7.4.6-4.module+el8.3.0+7685+72d70b58                   ol8_appstream                1.5 M
 php-json                    aarch64            7.4.6-4.module+el8.3.0+7685+72d70b58                   ol8_appstream                 73 k
 php-mbstring                aarch64            7.4.6-4.module+el8.3.0+7685+72d70b58                   ol8_appstream                474 k
 php-xml                     aarch64            7.4.6-4.module+el8.3.0+7685+72d70b58                   ol8_appstream                166 k
Installing dependencies:
 httpd-filesystem            noarch             2.4.37-39.0.1.module+el8.4.0+20024+b87b2deb            ol8_appstream                 39 k
 libxslt                     aarch64            1.1.32-6.0.1.el8                                       ol8_baseos_latest            239 k
 nginx-filesystem            noarch             1:1.14.1-9.0.1.module+el8.0.0+5347+9282027e            ol8_appstream                 25 k
Installing module profiles:
 php/common
Enabling module streams:
 httpd                                          2.4
 nginx                                          1.14
 php                                            7.4

Transaction Summary
==========================================================================================================================================
Install  9 Packages

Total download size: 5.9 M
Installed size: 23 M
Downloading Packages:
<略>
$

手順6: MySQL設定編

Oralce Linux 8ではわざわざ「MySQL 8.0 for Oracle Linux 8 (aarch64)」を用意していますが、よく見るとそこにmysql-serverはなく、メインのol8_appstream に含まれているという理由はよくわかりませんが、せっかくなのでそのまま使用します。

(ちなみにol8_appstreamではmariadb 10.3と10.5も提供されていますので変更することもできます)

$ sudo dnf install mysql-server -y
Last metadata expiration check: 0:56:46 ago on Thu 27 May 2021 01:04:16 PM JST.
Dependencies resolved.
================================================================================
 Package      Arch    Version                               Repository     Size
================================================================================
Installing:
 mysql-server aarch64 8.0.21-1.module+el8.2.0+7793+cfe2b687 ol8_appstream  28 M
Installing dependencies:
 mariadb-connector-c-config
              noarch  3.1.11-2.el8_3                        ol8_appstream  15 k
 mecab        aarch64 0.996-1.module+el8.0.0+5253+1dce7bb2.9
                                                            ol8_appstream 367 k
 mysql        aarch64 8.0.21-1.module+el8.2.0+7793+cfe2b687 ol8_appstream  13 M
 mysql-common aarch64 8.0.21-1.module+el8.2.0+7793+cfe2b687 ol8_appstream 147 k
 mysql-errmsg aarch64 8.0.21-1.module+el8.2.0+7793+cfe2b687 ol8_appstream 581 k
 protobuf-lite
              aarch64 3.5.0-13.el8                          ol8_appstream 129 k
Enabling module streams:
 mysql                8.0

Transaction Summary
================================================================================
Install  7 Packages

Total download size: 42 M
Installed size: 228 M
Downloading Packages:
<略>
$

mysqldを自動起動する設定とします。

$ sudo systemctl enable mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
$

mysqldを起動します。

$ sudo systemctl start mysqld
$

WordPress用データベースを作成します。

MySQL 8におけるデータベースユーザ作成と権限の割り当てが従来の「grant all on DB名.* to wordpress@localhost identified by ‘パスワード’;」という一文から、「create user ~」と「grant ~」の2つに分かれている点に注意が必要です。

$ sudo mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.21 Source distribution

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database DB名 character set utf8;
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> create user wordpress@localhost  identified by 'パスワード';
Query OK, 0 rows affected (0.01 sec)

mysql> grant all privileges on DB名.* to wordpress@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
$

手順7: Webサーバ設定

手順7-1: httpdインストール

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

Oracle Linux 8では httpd(Apache) 2.4と nginx 1.14 / 1.16 / 1.18 が使用できますが、httpdを使用します。nginxを使用したい場合は「Oracle Autonomous Linuxでwordpressサーバを建ててみた」を参照してください。

$ sudo dnf install httpd -y
Last metadata expiration check: 0:08:49 ago on Thu 27 May 2021 01:04:16 PM JST.
Dependencies resolved.
==========================================================================================================================================
 Package                      Architecture      Version                                                 Repository                   Size
==========================================================================================================================================
Installing:
 httpd                        aarch64           2.4.37-39.0.1.module+el8.4.0+20024+b87b2deb             ol8_appstream               1.4 M
Installing dependencies:
 apr                          aarch64           1.6.3-11.el8                                            ol8_appstream               119 k
 apr-util                     aarch64           1.6.1-6.el8                                             ol8_appstream               104 k
 httpd-tools                  aarch64           2.4.37-39.0.1.module+el8.4.0+20024+b87b2deb             ol8_appstream               104 k
 mod_http2                    aarch64           1.15.7-3.module+el8.4.0+20024+b87b2deb                  ol8_appstream               146 k
 oracle-logos-httpd           noarch            84.3-1.0.1.el8                                          ol8_baseos_latest            29 k

Transaction Summary
==========================================================================================================================================
Install  6 Packages

Total download size: 1.8 M
Installed size: 10 M
Downloading Packages:
<略>
$

次で設定変更をするので、この段階ではhttpdを起動しません。

OS起動時に自動起動する設定だけを行います。

$ sudo systemctl enable httpd
$

手順7-2: dehydratedによるLet’s Encrypt導入

Let’s EncryptによるSSL証明書導入はcertbotを使うのが一般的ではあるのだが、python環境とあわせてパッケージサイズが大きいので、コンパクトでEPELにも収録されているdehydratedを使用する。

$ sudo dnf install dehydrated -y
Last metadata expiration check: 1:07:45 ago on Thu 27 May 2021 01:04:16 PM JST.
Dependencies resolved.
================================================================================
 Package          Architecture Version           Repository                Size
================================================================================
Installing:
 dehydrated       noarch       0.6.5-1.el8       ol8_developer_EPEL        90 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 90 k
Installed size: 164 k
Downloading Packages:
<略>
$

dehydratedによるSSL証明書取得処理には /var/www/dehydrated が使用されるためディレクトリを作成します。

$ sudo mkdir  /var/www/dehydrated
$

http://~/.well-known/acme-challenge でアクセスした時に上記ディレクトリが開くようApacheの設定を /etc/httpd/conf.d/dehydrated.conf として作成します。(sudo vi /etc/httpd/conf.d/dehydrated.conf )

$ sudo vi /etc/httpd/conf.d/dehydrated.conf
$ cat /etc/httpd/conf.d/dehydrated.conf
Alias /.well-known/acme-challenge /var/www/dehydrated
<Directory /var/www/dehydrated/>
</Directory>
$

httpdを起動します

$ sudo systemctl start httpd
$

SSL証明書を発行するホスト名を /etc/dehydrated/domains.txt に記載する。(sudo vi /etc/dehydrated/domains.txt)

1行に複数のホスト名を記載するとaliasになります。

$ sudo vi /etc/dehydrated/domains.txt
$ sudo cat /etc/dehydrated/domains.txt
ホスト1名.ドメイン名 ホスト2名.ドメイン名
$

登録操作を開始します。

$ sudo dehydrated --register
# INFO: Using main config file /etc/dehydrated/config
# INFO: Using additional config file /etc/dehydrated/conf.d/local.sh

To use dehydrated with this certificate authority you have to agree to their terms of service which you can find here: https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf

To accept these terms of service run `/bin/dehydrated --register --accept-terms`.
$ sudo /bin/dehydrated --register --accept-terms
# INFO: Using main config file /etc/dehydrated/config
# INFO: Using additional config file /etc/dehydrated/conf.d/local.sh
+ Generating account key...
+ Registering account key with ACME server...
+ Fetching account ID...
+ Done!
$

初回のSSL証明書発行処理を実行します。

$ sudo dehydrated --cron
# INFO: Using main config file /etc/dehydrated/config
# INFO: Using additional config file /etc/dehydrated/conf.d/local.sh
Processing ホスト1名.ドメイン名 with alternative names: ホスト2名.ドメイン名
 + Signing domains...
 + Generating private key...
 + Generating signing request...
 + Requesting new certificate order from CA...
 + Received 2 authorizations URLs from the CA
 + Handling authorization for ホスト1名.ドメイン名
 + Handling authorization for ホスト2名.ドメイン名
 + 2 pending challenge(s)
 + Deploying challenge tokens...
 + Responding to challenge for ホスト1名.ドメイン名 authorization...
 + Challenge is valid!
 + Responding to challenge for ホスト2名.ドメイン名 authorization...
 + Challenge is valid!
 + Cleaning challenge tokens...
 + Requesting certificate...
 + Checking certificate...
 + Done!
 + Creating fullchain.pem...
 + Done!
$

手順7-3: WebサーバへのSSL証明書設定

まず、httpdにmod_sslを追加します。

$ sudo dnf install mod_ssl -y
Last metadata expiration check: 1:36:21 ago on Thu 27 May 2021 01:04:16 PM JST.
Dependencies resolved.
================================================================================
 Package
      Arch    Version                                       Repository     Size
================================================================================
Installing:
 mod_ssl
      aarch64 1:2.4.37-39.0.1.module+el8.4.0+20024+b87b2deb ol8_appstream 126 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 126 k
Installed size: 274 k
Downloading Packages:
<略>
$

標準の /etc/httpd/conf.d/ssl.conf は使わず、Mozilla SSL Configuration Generatorベースの設定を /etc/httpd/conf.d/ssl-mozilla.conf として作成します。(なお、ssl.conf には”Listen 443 https”設定もあるので、そのままにしています)

$ sudo vi /etc/httpd/conf.d/ssl-mozilla.conf
$ cat /etc/httpd/conf.d/ssl-mozilla.conf
# generated 2021-05-27, Mozilla Guideline v5.6, Apache 2.4.37, OpenSSL 1.1.1g, intermediate configuration
# https://ssl-config.mozilla.org/#server=apache&version=2.4.37&config=intermediate&openssl=1.1.1g&guideline=5.6

# this configuration requires mod_ssl, mod_socache_shmcb, mod_rewrite, and mod_headers
<VirtualHost *:80>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/\.well\-known/acme\-challenge/
    RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>

<VirtualHost *:443>
    SSLEngine on

    # curl https://ssl-config.mozilla.org/ffdhe2048.txt >> /path/to/signed_cert_and_intermediate_certs_and_dhparams
    SSLCertificateFile      /etc/dehydrated/certs/<ホスト名>/cert.pem
    SSLCertificateKeyFile   /etc/dehydrated/certs/<ホスト名>/privkey.pem

    # enable HTTP/2, if available
    Protocols h2 http/1.1

    # HTTP Strict Transport Security (mod_headers is required) (63072000 seconds)
    Header always set Strict-Transport-Security "max-age=63072000"
</VirtualHost>

# intermediate configuration
SSLProtocol             all -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite          ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
SSLHonorCipherOrder     off
SSLSessionTickets       off

SSLUseStapling On
SSLStaplingCache "shmcb:logs/ssl_stapling(32768)"
$

httpdを再起動します。

$ sudo systemctl restart httpd
$

手順8: WordPress導入

手順8-1: WordPressの基本インストール

WordPressのWebから最新版をダウンロードして、/var/www/html以下に展開します。
(日本語環境向けのlatest-ja.tar.gzファイルを使っていないのはWordpressプラグインが正常にインストールできるかを確認するためにWP Multibyte Patchを手動インストールする手順を入れているためです)

$ cd /var/www/html/
$ ls
$ sudo curl -O https://wordpress.org/latest.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 15.0M  100 15.0M    0     0  6978k      0  0:00:02  0:00:02 --:--:-- 6978k
$ ls
latest.tar.gz
$ sudo tar xfz latest.tar.gz
$ ls -l
total 15388
-rw-r--r--. 1 root   root   15750424 May 27 14:54 latest.tar.gz
drwxr-xr-x. 5 nobody nobody     4096 May 13 08:49 wordpress
$ sudo rm latest.tar.gz
$

WordPressディレクトリの所有者をWebサービスのユーザである「apache」に変更します。

$ ps -ef|grep http
root        7619       1  0 14:52 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache      7621    7619  0 14:52 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache      7622    7619  0 14:52 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache      7623    7619  0 14:52 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache      7624    7619  0 14:52 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache      7836    7619  0 14:52 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
opc         7943    2643  0 14:55 pts/0    00:00:00 grep --color=auto http
$ sudo chown -R apache:apache wordpress/
$ ls -l
total 4
drwxr-xr-x. 5 apache apache 4096 May 13 08:49 wordpress
$

/var/www/html/wordpress をDocumentRootとするように ssl-mozilla.conf に追加して、httpdを再起動します。

$ sudo vi /etc/httpd/conf.d/ssl-mozilla.conf
$ cat /etc/httpd/conf.d/ssl-mozilla.conf
# generated 2021-05-27, Mozilla Guideline v5.6, Apache 2.4.37, OpenSSL 1.1.1g, intermediate configuration
# https://ssl-config.mozilla.org/#server=apache&version=2.4.37&config=intermediate&openssl=1.1.1g&guideline=5.6

# this configuration requires mod_ssl, mod_socache_shmcb, mod_rewrite, and mod_headers
<VirtualHost *:80>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/\.well\-known/acme\-challenge/
    RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>

<VirtualHost *:443>
    DocumentRoot /var/www/html/wordpress
    SSLEngine on

    # curl https://ssl-config.mozilla.org/ffdhe2048.txt >> /path/to/signed_cert_and_intermediate_certs_and_dhparams
    SSLCertificateFile      /etc/dehydrated/certs/<ホスト名>/cert.pem
    SSLCertificateKeyFile   /etc/dehydrated/certs/<ホスト名>/privkey.pem

    # enable HTTP/2, if available
    Protocols h2 http/1.1

    # HTTP Strict Transport Security (mod_headers is required) (63072000 seconds)
    Header always set Strict-Transport-Security "max-age=63072000"
</VirtualHost>

# intermediate configuration
SSLProtocol             all -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite          ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
SSLHonorCipherOrder     off
SSLSessionTickets       off

SSLUseStapling On
SSLStaplingCache "shmcb:logs/ssl_stapling(32768)"
$ sudo systemctl restart httpd
$

手順8-2:「Service Unavailable」となる場合の対処

ブラウザからアクセスして「Service Unavailable」となる場合はphp-fpmのSELinux設定問題が発生しています。

httpd_execmemを有効にします。

$ getsebool httpd_execmem
httpd_execmem --> off
$ sudo setsebool -P httpd_execmem on
$ sudo getsebool httpd_execmem
httpd_execmem --> on
$

次に、php-fpm用のSELinux設定を作成します。まず「sudo ausearch -m AVC |grep php |audit2allow」を実行して「allow ~」の出力があることを確認

$ sudo ausearch -m AVC |grep php |audit2allow


#============= httpd_t ==============
allow httpd_t httpd_exec_t:file execmod;
$

次にこれを使ってSELinux用のモジュールを作成

$ sudo ausearch -m AVC |grep php |sudo audit2allow -M ph
p-fpm
******************** IMPORTANT ***********************
To make this policy package active, execute:

semodule -i php-fpm.pp

$ ls
php-fpm.pp  php-fpm.te  wordpress
$

モジュールとして組み込みphp-fpmを起動

$ sudo semodule -i php-fpm.pp
$ sudo systemctl start php-fpm
$ 

手順8-3: 「missing the MySQL extension」がでる場合の手順

php-fpmが正常に動作している状態でブラウザからアクセスすると、下記の表示になります。

これはphpからMySQLにアクセスするためのパッケージがインストールされていないためなので、php-mysqlndを追加して、httpdを再起動します。

$ sudo dnf install php-mysqlnd -y
Last metadata expiration check: 1:56:37 ago on Thu 27 May 2021 01:04:16 PM JST.
Dependencies resolved.
================================================================================
 Package     Arch    Version                                Repository     Size
================================================================================
Installing:
 php-mysqlnd aarch64 7.4.6-4.module+el8.3.0+7685+72d70b58   ol8_appstream 182 k
Installing dependencies:
 php-pdo     aarch64 7.4.6-4.module+el8.3.0+7685+72d70b58   ol8_appstream 118 k

Transaction Summary
================================================================================
Install  2 Packages

Total download size: 300 k
Installed size: 806 k
Downloading Packages:
<略>
$ sudo systemctl restart httpd
$

WordPressの設定手順を進めると wp-config.php に書き込めない、と出ますので、「sudo vi /var/www/html/wordpress/wp-config.php」を実行し、指定された内容を記載します。

手順9: SELinux設定

手順9-1: httpdのネットワーク接続問題

一見するとここまででうまく動いているように見えます。

しかし、プラグインをインストールしようとするとエラーになります。

/var/log/audit/audit.logを確認すると下記のようなログが出ています。

type=AVC msg=audit(1622095859.957:2064): avc:  denied  { name_connect } for  pid=8908 comm="php-fpm" dest=443 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:http_port_t:s0 tclass=tcp_socket permissive=0
type=AVC msg=audit(1622095868.397:2065): avc:  denied  { name_connect } for  pid=8313 comm="php-fpm" dest=443 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:http_port_t:s0 tclass=tcp_socket permissive=0
type=AVC msg=audit(1622095868.401:2066): avc:  denied  { name_connect } for  pid=8313 comm="php-fpm" dest=80 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:http_port_t:s0 tclass=tcp_socket permissive=0

これはhttpd_can_network_connect という値で制御されている

現在の設定値を「sudo getsebool -a |grep httpd_can_network」で確認し、「sudo setsebool -P httpd_can_network_connect on」で有効にする

$ sudo getsebool -a |grep httpd_can_network
httpd_can_network_connect --> off
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> off
httpd_can_network_memcache --> off
httpd_can_network_relay --> off
$ sudo setsebool -P httpd_can_network_connect on
$ sudo getsebool -a |grep httpd_can_network
httpd_can_network_connect --> on
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> off
httpd_can_network_memcache --> off
httpd_can_network_relay --> off
$

この変更ではhttpdの再起動は不要。

手順9-2: php-fpmの書き込み権限問題

プラグインやテーマのインストールについては問題なくても、WordPressのアップデートが出来ない。

このときの/var/log/audit/audit.logは下記

type=AVC msg=audit(1622101524.977:177): avc:  denied  { write } for  pid=2964 comm="php-fpm" name="wordpress" dev="dm-0" ino=101235463 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:httpd_sys_content_t:s0 tclass=dir permissive=0

こちらは/var/www/html/wordpress に対して httpdから書き込みが行えるような SELinuxのコンテキストをつけることで解決する。

「sudo chcon -R -t httpd_sys_script_rw_t /var/www/html/wordpress」

$ ls -lZ /var/www/html/
total 4
drwxr-xr-x. 5 apache apache unconfined_u:object_r:httpd_sys_content_t:s0 4096 May 27 15:02 wordpress
$ sudo chcon -R -t httpd_sys_script_rw_t /var/www/html/wordpress
$ ls -lZ /var/www/html/
total 4
drwxr-xr-x. 5 apache apache unconfined_u:object_r:httpd_sys_rw_content_t:s0 4096 May 27 15:02 wordpress
$

手順9-3:Wordpressプラグイン追加の動作確認

WordPressプラグインがインストールできる状態になっているかを確認するために「WP Multibyte Patch」をインストールします。

これをインストールするとWordpressの設定画面([Settings]-[General])に「Site language(サイトの言語)」が追加され、「日本語」表示に切り替えることができるようになります。

手順10: WordPressで取り扱えるファイルサイズの拡大

WordPressで取り扱えるファイルは標準状態だと2MBになっている。

WordPressのドキュメントのFile Upload Sizes を見ると、これはphpの設定ファイル /etc/php.ini による制限となっている。

Oracle Linux 8の標準設定では下記の値となっている。

<略>
post_max_size = 8M
<略>
upload_max_filesize = 2M
<略>

で・・・よくある手順だと軽率に /etc/php.ini を書き換えていますが、 /etc/php.d/ 以下にファイルを追加することで、そちらの設定項目を優先させることができる機能があるため、 /etc/php.d/90-wordpress.ini に変更したい2行だけを記載したファイルを作成します。

$ sudo vi /etc/php.d/90-wordpress.ini
$ cat /etc/php.d/90-wordpress.ini
post_max_size = 100M
upload_max_filesize = 100M
$

phpの設定変更を反映させるために「sudo systemctl restart php-fpm」を実行します。

手順11: WordPressのSite Health Status対応

WordPressのサイトステータスを見てみると、いくつかパッケージを要求されている。

ImageMagickに関するphpモジュールは含まれていない

$ dnf search magick
Last metadata expiration check: 2:56:09 ago on Thu 27 May 2021 01:10:22 PM JST.
======================== Name & Summary Matched: magick ========================
GraphicsMagick.aarch64 : An ImageMagick fork, offering faster image generation
                       : and better quality
GraphicsMagick.src : An ImageMagick fork, offering faster image generation and
                   : better quality
GraphicsMagick-c++.aarch64 : GraphicsMagick Magick++ library (C++ bindings)
GraphicsMagick-c++-devel.aarch64 : C++ bindings for the GraphicsMagick library
GraphicsMagick-debugsource.aarch64 : Debug sources for package GraphicsMagick
GraphicsMagick-devel.aarch64 : Libraries and header files for GraphicsMagick app
                             : development
GraphicsMagick-doc.noarch : GraphicsMagick documentation
GraphicsMagick-perl.aarch64 : GraphicsMagick perl bindings
ImageMagick-c++.aarch64 : ImageMagick Magick++ library (C++ bindings)
ImageMagick-c++-devel.aarch64 : C++ bindings for the ImageMagick library
ImageMagick-devel.aarch64 : Library links and header files for ImageMagick app
                          : development
ImageMagick-doc.aarch64 : ImageMagick html documentation
ImageMagick-libs.aarch64 : ImageMagick libraries to link with
ImageMagick-perl.aarch64 : ImageMagick perl bindings
============================= Name Matched: magick =============================
ImageMagick.aarch64 : An X application for displaying and manipulating images
ImageMagick.src : An X application for displaying and manipulating images
=========================== Summary Matched: magick ============================
converseen.aarch64 : A batch image conversion tool written in C++ with Qt5 and
                   : Magick++
converseen.src : A batch image conversion tool written in C++ with Qt5 and
               : Magick++
$

zipとgdはそれっぽいものがあるので「sudo dnf install php-pecl-zip php-gd -y」で追加

$ sudo dnf install php-pecl-zip php-gd -y
Last metadata expiration check: 3:04:44 ago on Thu 27 May 2021 01:04:16 PM JST.
Dependencies resolved.
================================================================================
 Package      Arch    Version                               Repository     Size
================================================================================
Installing:
 php-gd       aarch64 7.4.6-4.module+el8.3.0+7685+72d70b58  ol8_appstream  83 k
 php-pecl-zip aarch64 1.18.2-1.module+el8.3.0+7685+72d70b58 ol8_appstream  53 k
Installing dependencies:
 gd           aarch64 2.2.5-7.el8                           ol8_appstream 134 k
 jbigkit-libs aarch64 2.1-14.el8                            ol8_appstream  54 k
 libXpm       aarch64 3.5.12-8.el8                          ol8_appstream  56 k
 libjpeg-turbo
              aarch64 1.5.3-10.el8                          ol8_appstream 145 k
 libtiff      aarch64 4.0.9-18.el8                          ol8_appstream 178 k
 libwebp      aarch64 1.0.0-1.el8                           ol8_appstream 246 k
 libzip       aarch64 1.6.1-1.module+el8.3.0+7685+72d70b58  ol8_appstream  62 k

Transaction Summary
================================================================================
Install  9 Packages

Total download size: 1.0 M
Installed size: 3.0 M
Downloading Packages:
<略>
$

こちらは再起動は不要なようで、すぐにSite Healthの状態に反映され、imagickモジュールに関するメッセージのみになった。

2022/04/06追記: wordpress 5.9.3では推奨phpプラグインに「php-intl」が追加されたので「sudo dnf install php-intl」で追加する

$ sudo dnf install php-intl
This system is receiving updates from OSMS server.
Last metadata expiration check: 0:09:17 ago on Wed 06 Apr 2022 01:29:10 PM JST.
Dependencies resolved.
================================================================================
 Package
     Arch    Version                                Repository             Size
================================================================================
Installing:
 php-intl
     aarch64 7.4.19-1.module+el8.5.0+20354+db97279a ol8_appstream-aarch64 182 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 182 k
Installed size: 522 k
Is this ok [y/N]: y
Downloading Packages:
php-intl-7.4.19-1.module+el8.5.0+20354+db97279a 2.0 MB/s | 182 kB     00:00
--------------------------------------------------------------------------------
Total                                           1.9 MB/s | 182 kB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1
  Installing       : php-intl-7.4.19-1.module+el8.5.0+20354+db97279a.aarc   1/1
  Running scriptlet: php-intl-7.4.19-1.module+el8.5.0+20354+db97279a.aarc   1/1
  Verifying        : php-intl-7.4.19-1.module+el8.5.0+20354+db97279a.aarc   1/1

Installed:
  php-intl-7.4.19-1.module+el8.5.0+20354+db97279a.aarch64

Complete!
$

手順12: WordPressの.htaccess有効化

/var/www/html/wordpress/.htaccess が作成されているが、Oracle Linux 8のhttpd標準設定ではこれを読み込むようにはなっていない。

これが有効になっていないと、パーマリンク設定を「基本」から変えた場合に個別記事にアクセスできなくなる。

/etc/httpd/conf.d/wordpress.conf にファイルを作って設定する。

$ sudo vi /etc/httpd/conf.d/wordpress.conf
$ cat /etc/httpd/conf.d/wordpress.conf
<Directory /var/www/html/wordpress/>
 Allowoverride All
</Directory>
$ sudo systemctl restart httpd
$

手順13: OS自動更新の設定

メンテナンスがめんどくさくなって忘れる可能性があるので、Oracle Linux 8の自動更新設定を実施。

以前はyum-cronでしたが、現在は dnf-automatic に変わったので、パッケージをインストールします。

$ sudo dnf install dnf-automatic -y
Last metadata expiration check: 0:21:33 ago on Wed 02 Jun 2021 05:00:20 PM JST.
Dependencies resolved.
================================================================================
 Package            Arch        Version            Repository              Size
================================================================================
Installing:
 dnf-automatic      noarch      4.4.2-11.el8       ol8_baseos_latest      148 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 148 k
Installed size: 51 k
Downloading Packages:
<略>
$

/etc/dnf/automatic.conf 内の「apply_updates = no」を「apply_updates = yes」に変更

$ sudo vi /etc/dnf/automatic.conf
$ cat /etc/dnf/automatic.conf
[commands]
#  What kind of upgrade to perform:
# default                            = all available upgrades
# security                           = only the security upgrades
upgrade_type = default
random_sleep = 0

# Maximum time in seconds to wait until the system is on-line and able to
# connect to remote repositories.
network_online_timeout = 60

# To just receive updates use dnf-automatic-notifyonly.timer

# Whether updates should be downloaded when they are available, by
# dnf-automatic.timer. notifyonly.timer, download.timer and
# install.timer override this setting.
download_updates = yes

# Whether updates should be applied when they are available, by
# dnf-automatic.timer. notifyonly.timer, download.timer and
# install.timer override this setting.
apply_updates = yes


[emitters]
# Name to use for this system in messages that are emitted.  Default is the
# hostname.
# system_name = my-host

# How to send messages.  Valid options are stdio, email and motd.  If
# emit_via includes stdio, messages will be sent to stdout; this is useful
# to have cron send the messages.  If emit_via includes email, this
# program will send email itself according to the configured options.
# If emit_via includes motd, /etc/motd file will have the messages. if
# emit_via includes command_email, then messages will be send via a shell
# command compatible with sendmail.
# Default is email,stdio.
# If emit_via is None or left blank, no messages will be sent.
emit_via = stdio


[email]
# The address to send email messages from.
email_from = root@example.com

# List of addresses to send messages to.
email_to = root

# Name of the host to connect to to send email messages.
email_host = localhost


[command]
# The shell command to execute. This is a Python format string, as used in
# str.format(). The format function will pass a shell-quoted argument called
# `body`.
# command_format = "cat"

# The contents of stdin to pass to the command. It is a format string with the
# same arguments as `command_format`.
# stdin_format = "{body}"


[command_email]
# The shell command to use to send email. This is a Python format string,
# as used in str.format(). The format function will pass shell-quoted arguments
# called body, subject, email_from, email_to.
# command_format = "mail -Ssendwait -s {subject} -r {email_from} {email_to}"

# The contents of stdin to pass to the command. It is a format string with the
# same arguments as `command_format`.
# stdin_format = "{body}"

# The address to send email messages from.
email_from = root@example.com

# List of addresses to send messages to.
email_to = root


[base]
# This section overrides dnf.conf

# Use this to filter DNF core messages
debuglevel = 1
$

そしてdnf-automatic.timerを有効化し、開始します。

$ sudo systemctl enable dnf-automatic.timer
Created symlink /etc/systemd/system/timers.target.wants/dnf-automatic.timer → /usr/lib/systemd/system/dnf-automatic.timer.
$ sudo systemctl status dnf-automatic
● dnf-automatic.service - dnf automatic
   Loaded: loaded (/usr/lib/systemd/system/dnf-automatic.service; static; vendo>
   Active: inactive (dead)
$ sudo systemctl start dnf-automatic.timer
$ sudo systemctl status dnf-automatic.timer
● dnf-automatic.timer - dnf-automatic timer
   Loaded: loaded (/usr/lib/systemd/system/dnf-automatic.timer; enabled; vendor>
   Active: active (waiting) since Wed 2021-06-02 17:26:38 JST; 2s ago
  Trigger: Thu 2021-06-03 06:07:23 JST; 12h left

Jun 02 17:26:38 ホスト名 systemd[1]: Started dnf-automatic timer.
$

なお、dnf automaticでアップデートされた場合に、通知メールを送るようにする場合は、「Oracle Cloud上のインスタンスから管理メールを送信する手法」を参照のこと。

Let’s Encrypt対抗サービスのStart Encrypt



StartSSLというSSL証明書発行サービスをやっているStartComが、Let’s Encrypt対抗サービスとなる「Start Encrypt」というものを開始しようとしています。

プレスリリース「StartCom launches a new service – StartEncrypt」(2016/06/06)

(2016/08/08現在、「Coming soon」表記のままなのが謎・・・公開当初はクライアントバイナリも公開されてた気がするのですが・・・)

Let’s Encryptとの違いはちゃんとあります。
https://docs.google.com/spreadsheets/d/1fd43Gx6Xtn_Cz5ivrl-qJi_Ze1GGBufuTXPpyw-ZgjI/edit?usp=sharing

(表へのリンク)


2017/01/12追記

なんか開始早々巨大なバグがあったらしく、サービスが停止してしまったそうで、いまはページも消失してますね
「StartSSL Free」という3年間有効で10ドメインまでというやつをやってますが、それはAPI対応とか無い感じですね

CentOS5などの古い環境でLet’s Encryptを使う(2017/02/21更新)


フリーで90日有効のSSL証明書を取得できる「Let’s Encrypt

90日毎に更新する必要があるため、プログラムを実行して証明書の取得ができるようになっている。

公式のプログラム(クライアント)は「https://github.com/certbot/certbot」にあるが、CentOS6以降やUbuntu向けに作られており、古いPythonの環境であるCentOS5では動作させるのが大変である。

公式以外のクライアントを探すと、「List of Client Implementations」に互換クライアント一覧がある。

いろいろある中で、2016年1月時点では唯一のbash環境用のスクリプトだった「Shell script client: dehydrated (旧名letsencrypt.sh) 」を選択。(なお、2017年2月現在では他にも3つ出ている。)

dehydratedは、「opensslコマンド」「curlコマンド」「sedコマンド」「grepコマンド」があれば動作する。

— 2018/07/20 追記開始 —
CentOS7環境で公式のcertbotを使って運用しようとしたのですが、alias FQDNを増やす際に別の設定が作られてしまうとか、管理性があまりよろしくなかったので、CentOS7環境でも制御しやすいdehydratedを使ってます。
— 2018/07/20 追記終わり —

(1) 「git clone https://github.com/lukas2511/dehydrated.git」でプログラム取得

(2) SSL証明書発行時に使用する一時ディレクトリの設定

SSL証明書発行時、Let’s Encryptサーバから「http://ドメイン名/.well-known/acme-challenge/~」というアクセスが行われる。その際のファイルを置く場所を用意する。

ここでは/var/www/dehydratedディレクトリに置くことにする。

1. /var/www/dehydratedディレクトリ作成
2. Aapacheの設定で「/etc/httpd/conf.d/dehydrated.conf」を作成

Alias /.well-known/acme-challenge /var/www/dehydrated
<Directory /var/www/dehydrated/>
</Directory>

3. Aapacheの再起動

(3) configを作成

docs/examples/config を元にconfigを作成する。

基本的には初期状態のままで良いが、2で/var/www/dehydrated以外を指定した場合に下記の記述を変更する

WELLKNOWN="/var/www/dehydrated/"

(4) domains.txtを作成

SSL証明書を発行したいドメインをスペース区切りで列挙する。

blog.osakana.net blog2.osakana.net

(5) dehydratedを実行して、まずはアカウント登録

# ./dehydrated --config /~/dehydrated/config --register --accept-terms
# INFO: Using main config file ./config
+ Generating account key...
+ Registering account key with ACME server...
+ Done!
#

実行すると下記の様にaccountsディレクトリが作成される。

# ls -F
CHANGELOG  README.md  config       docs/        test.sh*
LICENSE    accounts/  dehydrated*  domains.txt
# ls -F accounts/
~~~/
#

(6) もう一度、dehydratedを実行してSSL証明書を発行

# ./dehydrated --config ./config --cron
# INFO: Using main config file ./config
Processing ~ ~ ~
 + Signing domains...
 + Creating new directory ./certs/blog.osakana.net ...
 + Generating private key...
 + Generating signing request...
 + Requesting challenge for ~...
 + Requesting challenge for ~...
<略>
 + Responding to challenge for ~...
 + Challenge is valid!
 + Responding to challenge for ~...
 + Challenge is valid!
 + Requesting certificate...
 + Checking certificate...
 + Done!
 + Creating fullchain.pem...
 + Done!
#

下記の様にcertsディレクトリ以下にファイルが作成される。

# ls -F
CHANGELOG  README.md  certs/  dehydrated*  domains.txt
LICENSE    accounts/  config  docs/        test.sh*
# ls -F certs/
~/
# ls -F certs/~/
cert-xxxxxxxxxx.csr  chain-xxxxxxxxxx.pem      privkey-xxxxxxxxxx.pem
cert-xxxxxxxxxx.pem  chain.pem@                privkey.pem@
cert.csr@            fullchain-xxxxxxxxxx.pem
cert.pem@            fullchain.pem@
[root@niselog dehydrated]#

(7) Apache設定内のSSLファイルの指定では、作成されたファイルのうち、fullchain.pemとprivkey.pem,chain.pemを指定する。

SSLCertificateFile /~/certs/~/fullchain.pem
SSLCertificateKeyFile /~/certs/~/privkey.pem
SSLCertificateChainFile /~/certs/~/chain.pem

なお、最近は問題無いが、バージョンアップしていない古いブラウザでは、「SSLCertificateChainFile /~/certs/~/chain.pem」を抜いた2行で設定するとエラーが発生する場合があるので注意が必要。

(8) httpsアクセスをして問題無いことを確認

ブラウザからhttpsアクセスを行い、想定通りにアクセスできることを確認。

(9) crontabに、dehydratedを定期的に実行する設定を追加

毎月1日と15日に実行する処理

# crontab -l
0 3 1,15 * * /~/dehydrated/dehydrated --config /~/dehydrated/config --cron >> /tmp/ssl-update.log 2>&1
#

以下は旧バージョン

 


フリーで90日有効のSSL証明書を取得できる「Let’s Encrypt

 

90日毎に更新する必要があるため、プログラムを実行して証明書の取得ができるようになっている。
公式のプログラム(クライアント)は「https://github.com/letsencrypt/letsencrypt」にあるが、CentOS6以降やUbuntu向けに作られており、古いPythonの環境であるCentOS5では動作させるのが大変である。

公式以外のクライアントを探すと、「List of Client Implementations」に互換クライアント一覧がある。

いろいろある中で、一番制約が薄そうな「Shell script (and a little Perl) client: https://github.com/lukas2511/letsencrypt.sh」を選択。
「opensslコマンド」「curlコマンド」「sedコマンド」があれば動作する。
perlはこの一覧が作られた当初は必要だったようだが、2016/01/04時点では不要。公式のletsencryptコマンドから移行する場合に使用するimport-account.plコマンドを使う時だけ必要なようだ。

1. 「git clone https://github.com/lukas2511/letsencrypt.sh」でプログラム取得
2. SSL証明書発行時に使用する一時ディレクトリの設定
 SSL証明書発行時、Let’s Encryptサーバから「http://ドメイン名/.well-known/acme-challenge/~」という
 アクセスが行われる。その際のファイルを置く場所を用意する。
 ここでは/var/www/letsenryptディレクトリに置くことにする。
 (1) /var/www/letsencryptディレクトリ作成
 (2) Aapacheの設定で「/etc/httpd/conf.d/letsencrypt.conf」を作成

Alias /.well-known/acme-challenge /var/www/letsencrypt
&lt;Directory /var/www/letsencrypt/&gt;
&lt;/Directory&gt;


 (3) Aapacheの再起動

3. config.shを作成
 config.sh.exampleを元にconfig.shを作成
 といっても、下記の行を書くだけ
 

WELLKNOWN="/var/www/letsencrypt/"

4. domain.txtを作成
 SSL証明書を発行したいドメインをスペース区切りで列挙する。
 

blog.osakana.net blog2.osakana.net

5. letsencrypt.shを実行

# ./letsencrypt.sh --config /~/letsencrypt.sh/config.sh --cron
Using config file /~/letsencrypt.sh/config.sh
Processing blog.osakana.net with SAN: blog2.osakana.net
 + Signing domains...
 + make directory /~/letsencrypt.sh/certs/blog.osakana.net ...
 + Generating private key...
 + Generating signing request...
 + Requesting challenge for blog.osakana.net...
 + Responding to challenge for blog.osakana.net...
 + Challenge is valid!
 + Requesting challenge for blog2.osakana.net...
 + Responding to challenge for blog2.osakana.net...
 + Challenge is valid!
 + Requesting certificate...
 + Checking certificate...
 + Creating fullchain.pem...
 + Done!
#

下記の様にcertsディレクトリ以下にファイルが作成される。

# ls -F
certs/             domains.txt          import-certs.sh*  private_key.pem
config.sh          domains.txt.example  letsencrypt.sh*   README.md
config.sh.example  import-account.pl*   LICENSE           test.sh*
# ls -F certs/
blog.osakana.net/
# ls -F certs/blog.osakana.net/
cert-xxxxxxxxxx.csr  chain-xxxxxxxxxx.pem      privkey-xxxxxxxxxx.pem
cert-xxxxxxxxxx.pem  chain.pem@                privkey.pem@
cert.csr@            fullchain-xxxxxxxxxx.pem
cert.pem@            fullchain.pem@
#

Apache設定内のSSLファイルの指定では、作成されたファイルのうち、fullchain.pemとprivkey.pem,chain.pemを指定する。

SSLCertificateFile /~/certs/~/fullchain.pem
SSLCertificateKeyFile /~/certs/~/privkey.pem
SSLCertificateChainFile /~/certs/~/chain.pem

ちなみに、「SSLCertificateChainFile /~/certs/~/chain.pem」を抜いた2行で設定するとChromeやIEでは問題無いが、Firefoxでのみ「sec_error_unknown_issuer」のエラーがでる。
(なお、fullchain.pemとprivkey.pemを指定しているのは、標準のletsencryptを使った場合に生成されるapache用cocnfigファイルで使われていたから)


おまけ:CentOS4で使用する場合に必要になること

 

・curlの証明書問題
 → /usr/share/ssl/certs/ca-bundle.crt を更新する
  → OpenSSLが古いためにエラーが発生
   「curl: (35) error:0D0890A1:asn1 encoding routines:ASN1_verify:unknown message digest algorithm」
・OpenSSLが古い
 → /usr/local/openssl1とかに新しいバージョンをインストールして回避
  letsencrypt.shの冒頭に、PATHとLD_LIBRARY_PATHを定義して、こちらを優先するように設定
 → こっちのOpenSSLを使うcurlをコンパイル
・trコマンドが古い
 letsencrypt.shを実行すると「tr: オプションが違います — _」というエラー
 → 新しいバージョンのtrが含まれるcoreutilsを/usr/localにインストール
・bashコマンドが古い
 環境変数操作で「SAN+=~」ということをやってるがCentOS4のBASHでは非対応
 letsencrypt.shを修正して、CentOS4でも使える操作に変更
 「SAN+=”DNS:${altname}, “」→「SAN=”${SAN}DNS:${altname}, “」

・下記のエラーでうまく行かない

# ./letsencrypt.sh --cron --config /~/letsencrypt.sh/config.sh
Using config file /~/letsencrypt.sh/config.sh
Processing xxxxxx with SAN: xxxxx
 + Signing domains...
 + Generating private key...
 + Generating signing request...
 + Requesting challenge for xxxxxx...
  + ERROR: An error occurred while sending post-request to https://acme-v01.api.letsencrypt.org/acme/new-authz (Status 403)

Details:
{"type":"urn:acme:error:unauthorized","detail":"No registration exists matching provided key","status":403}  + Error: Can't retrieve challenges ()
#


 → 失敗した時のcertが悪さをしていた
  certsディレクトリの中身とprivate_key.pemを削除して再実行したところ成功