0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WordPressの引っ越し(Amazon Linux 2→AlmaLinux 10)

0
Last updated at Posted at 2026-04-18

概要

個人の備忘録メインのため、不備が多いかと思います。よろしければご指摘ください。
5年前にCentOS7からAmazon Linux 2に引っ越しましたが、Amazon Linux 2のサポート終了が迫ってきたため、AlmaLinux 10に引っ越しします。
今回もWebサーバーはNginxにします。

AlmaLinux

以下を参考にEC2インスタンスを起動します。

EC2

インスタンスの起動、Elastic IPの割り当て、セキュリティグループ設定は割愛します。

初期設定

基本、ルート権限で作業します。

$ sudo -s

1. ホスト名の変更

# vi /etc/hostname

2. タイムゾーンの設定

# timedatectl set-timezone Asia/Tokyo

3. 日本語対応

# dnf -y install langpacks-ja
…
# localectl set-locale LANG=ja_JP.UTF-8

4. SELinux無効化

# setenforce 0
# vi /etc/selinux/config
…
SELINUX=permissive ← enforcing から permissive に変更
…

5. 再起動

# reboot

Nginx、PHPインストール

# dnf -y install nginx php-mbstring php-fpm php-mysqlnd

MariaDBインストール

1. dnfでインストール

# dnf install mariadb-server

2. 文字コード設定

# vi /etc/my.cnf.d/mariadb-server.cnf
…
[mysqld]
character-set-server = utf8 ← 追記
…

3. 起動

# systemctl start mariadb
# systemctl enable mariadb

4. 初期設定

# mysql_secure_installation
…
Enter current password for root (enter for none): ← 空Enter
…
Switch to unix_socket authentication [Y/n] ← 空Enter
…
Change the root password? [Y/n] ← 空Enter
New password: ← rootパスワード
Re-enter new password: ← rootパスワード
…
Remove anonymous users? [Y/n] ← 空Enter
…
Disallow root login remotely? [Y/n] ← 空Enter
…
Remove test database and access to it? [Y/n] ← 空Enter
…
Reload privilege tables now? [Y/n] ← 空Enter
…

WordPress用の設定

MariaDB

(前回同様)以下の設定とする。
データベース名:wordpress
ユーザー名:wordpress

# mysql -u root -p
> create database wordpress;
> grant all privileges on wordpress.* to wordpress@localhost identified by '(任意のパスワード)';

PHP-FPM

# vi /etc/php-fpm.d/www.conf
…
user = nginx ← apacheから変更
group = nginx ← 〃
…
# systemctl restart php-fpm
# systemctl enable php-fpm

旧サーバーからのデータ移動

1. 旧サーバー処理

旧サーバーのディレクトリは以下にある。
/usr/share/nginx/html/blog

### WordPress ###
# cd /usr/share/nginx/html
# tar zcvf blog.tar.gz blog
# mv blog.tar.gz (ec2-userユーザーのホームディレクトリ)

### MariaDB ###
# mysqldump wordpress -u wordpress -p > dump.sql
# mv dump.sql (ec2-userユーザーのホームディレクトリ)

2. 新サーバー処理

新サーバーのディレクトリも以下にする。
/usr/share/nginx/html/blog

### データコピー ###
# sftp -i (鍵ファイル).pem ec2-user@(旧サーバーのアドレス)
> get blog.tar.gz
> get dump.sql
> quit

### WordPress ###
# tar zxvf blog.tar.gz
# mv blog /usr/share/nginx/html/blog
# chown -R nginx. /usr/share/nginx/html/blog

### MariaDB ###
# mysql -u wordpress -p -D wordpress < dump.sql

HTTPS対応

Let's Encrypt導入

dnf install -y epel-release
dnf install -y certbot python3-certbot-nginx
# certbot --nginx
…
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): ← メールアドレスを入力してEnter
…
(Y)es/(N)o: ← 1回目ライセンス関連:Yを入力してEnter
…
(Y)es/(N)o: ← 2回目メールアドレスの共有:YかNを入力してEnter
…
name(s) (comma and/or space separated)  (Enter 'c' to cancel): fugiters.net ← ホスト名を入力してEnter
…

Nginx設定

設定ファイル(/etc/nginx/nginx.conf)の「Settings for a TLS enabled server.」の下の設定をコメントを外し、編集してnginxを再起動する。

# vi /etc/nginx/nginx.conf
…
    server {
        listen       443 ssl;
        listen       [::]:443 ssl;
        http2        on;
        server_name  fugiters.net; ← ホスト名
        root         /usr/share/nginx/html;

        ssl_certificate "/etc/letsencrypt/live/fugiters.net/cert.pem"; ← 証明書
        ssl_certificate_key "/etc/letsencrypt/live/fugiters.net/privkey.pem"; ← 秘密鍵
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout  10m;
#        ssl_ciphers PROFILE=SYSTEM; ← 不明
        ssl_prefer_server_ciphers on;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
    }
…
# systemctl restart nginx

感想

5年前の記事とほぼ同じ手順で移行できました。
違うのは参考URLが無いこと。
これは動かなかったコマンドを都度生成AI(Gemini先生)に聞きながらやったから。
(まあその分設定の漏れが無いとは言い切れない・汗)
時間も数時間で完了しました。
5年の技術の進歩を実感しました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?