さくらのVPSでCentOS7からAlmaLinux9へ移行する

はじめに

CentOS7が2024年6月30日でサポート期間が終了するということで、AlmaLinux9へ移行していきます。
現行サイトは止められないため、新しくサーバーを契約する必要があります。

【環境】
サーバー:さくらのVPS(v5) 4G IK01
移行前のOS:CentOS7
移行後のOS:AlmaLinux9

先日の記事でも書きましたが、ツールは使わず、手動でサーバー構築していきます。
さくらのVPSでCentOS7からAlmalinux9へ移行してみた→無理

移行前にチェックしたこと

OSのバージョン確認

[webuser@server ~]$ cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
[webuser@server ~]$ cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)

PHPのバージョン確認

[webuser@server ~]$ php -v
PHP 7.4.11 (cli) (built: Sep 29 2020 10:17:06) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

MySQLのバージョン確認

[webuser@server ~]$ mysqld --version
mysqld  Ver 5.7.31 for Linux on x86_64 (MySQL Community Server (GPL))

Apacheのバージョン確認

[webuser@server ~]$ httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built:   Apr  2 2020 13:13:23

CakePHPのバージョン確認

[webuser@server labo]$ bin/cake version
4.1.5

firewallの設定確認

[root@server webuser]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources:
  services: dhcpv6-client http
  ports: 80/tcp 443/tcp
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
	rule family="ipv4" source address="xxx.xxx.xxx.xxx" port port="22" protocol="tcp" accept
	rule family="ipv4" source address="yyy.yyy.yyy.yyy" port port="22" protocol="tcp" accept
	rule family="ipv4" source address="zzz.zzz.zzz.zzz" port port="22" protocol="tcp" accept

AlmaLinux9のサーバー契約

AlmaLinuxのインストール

まずは管理画面からOSをインストールします。

OS:AlmaLinux9

パケットフィルター設定
SSH TCP 22 送信元IPアドレス:すべて許可する
Web TCP 80/443 送信元IPアドレス:すべて許可する

historyコマンドに日付をつける

これは必須ではありませんが、僕の場合、コマンドの実行日時を結構見るので設定しておきます。

[root@server alma]# echo "export HISTTIMEFORMAT='%F %T '" >> ~/.bashrc
[root@server alma]# source ~/.bashrc

rootのパスワード設定

[root@server alma]# passwd
Changing password for user root.
New password: ← 新しいパスワードを入力
Retype new password: ← 新しいパスワードを入力
passwd: all authentication tokens updated successfully.

SSHの設定

/etc/ssh/sshd_config の編集

[root@server ~]# vi /etc/ssh/sshd_config
#PermitRootLogin prohibit-password
PermitRootLogin no ← これを追記


#PasswordAuthentication yes
PasswordAuthentication no ← これを追記
#PermitEmptyPasswords no
PermitEmptyPasswords no ← これを追記
[root@server ~]# systemctl restart sshd.service

ユーザーの追加

[root@server ~]# useradd webuser
[root@server ~]# passwd webuser
Changing password for user webuser.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

公開鍵・秘密鍵の作成

[webuser@server ~]$ ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/home/webuser/.ssh/id_rsa): ← Enter
Created directory '/home/webuser/.ssh'.
Enter passphrase (empty for no passphrase): ← Enter
Enter same passphrase again: 
Your identification has been saved in /home/webuser/.ssh/id_rsa ← 秘密鍵
Your public key has been saved in /home/webuser/.ssh/id_rsa.pub ← 公開鍵
The key fingerprint is:
SHA256:*********
The key's randomart image is:

id_rsaの内容をコピーして、クライアントPCに保存しておく。サーバーからは削除。
SSHで接続する際に使用します。
id_rsa.pubはauthorized_keysにリネームしてサーバーに置いておく

[webuser@server ~]$ rm ~/.ssh/id_rsa
[webuser@server ~]$ mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys

クライアントPCで、接続確認

% ssh -i id_rsa webuser@xxx.xxx.xxx.xxx
SAKURA internet [Virtual Private Server SERVICE]

Last login: Tue Feb 20 11:49:29 2024

Apacheのインストール

[root@server webuser]# yum list | grep httpd
httpd.x86_64                                         2.4.57-5.el9                        appstream
[root@server webuser]# yum install -y httpd
Installed:
  almalinux-logos-httpd-90.5.1-1.1.el9.noarch     apr-1.7.0-12.el9_3.x86_64           apr-util-1.6.1-23.el9.x86_64     apr-util-bdb-1.6.1-23.el9.x86_64     apr-util-openssl-1.6.1-23.el9.x86_64     httpd-2.4.57-5.el9.x86_64     httpd-core-2.4.57-5.el9.x86_64
  httpd-filesystem-2.4.57-5.el9.noarch            httpd-tools-2.4.57-5.el9.x86_64     mailcap-2.1.49-5.el9.noarch      mod_http2-1.15.19-5.el9.x86_64       mod_lua-2.4.57-5.el9.x86_64

Complete!

firewallの設定

firewalldの起動

[root@server webuser]# systemctl status firewalld
[root@server webuser]# systemctl start firewalld
[root@server webuser]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens3
  sources:
  services: cockpit dhcpv6-client ssh
  ports:
  protocols:
  forward: yes
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
[root@server webuser]# firewall-cmd --add-service=http --permanent
success
[root@server webuser]# firewall-cmd --add-port=80/tcp --permanent
success
[root@server webuser]# firewall-cmd --add-port=443/tcp --permanent
success
[root@server webuser]# systemctl restart firewalld

apacheの起動と自動起動登録

[root@server webuser]# systemctl start httpd
[root@server webuser]# systemctl enable httpd

PHP7.4のインストール

EPEL、Remiリポジトリのインストール

[root@server webuser]# yum install -y epel-release
Installed:
  epel-release-9-5.el9.noarch

Complete!
[root@server webuser]# yum install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm
Upgraded:
  almalinux-gpg-keys-9.3-1.el9.x86_64                                                     almalinux-release-9.3-1.el9.x86_64                                                     almalinux-repos-9.3-1.el9.x86_64
Installed:
  remi-release-9.3-3.el9.remi.noarch

Complete!

PHP7.4のインストール

[root@server webuser]# yum module install php:remi-7.4
Installed:
  libxslt-1.1.34-9.el9.x86_64             nginx-filesystem-1:1.20.1-14.el9_2.1.alma.1.noarch      oniguruma5php-6.9.9-1.el9.remi.x86_64      php-cli-7.4.33-10.el9.remi.x86_64      php-common-7.4.33-10.el9.remi.x86_64      php-fpm-7.4.33-10.el9.remi.x86_64
  php-json-7.4.33-10.el9.remi.x86_64      php-mbstring-7.4.33-10.el9.remi.x86_64                  php-xml-7.4.33-10.el9.remi.x86_64

Complete!
[root@server webuser]# yum module enable php:remi-7.4
[root@server webuser]# yum install php php-devel php-mbstring php-pdo php-gd php-xml php-mcrypt php-intl
Upgraded:
  elfutils-libelf-0.189-3.el9.x86_64 elfutils-libs-0.189-3.el9.x86_64   glibc-2.34-83.el9_3.7.x86_64         glibc-common-2.34-83.el9_3.7.x86_64 glibc-gconv-extra-2.34-83.el9_3.7.x86_64 glibc-langpack-en-2.34-83.el9_3.7.x86_64 krb5-libs-1.21.1-1.el9.x86_64
  libgcc-11.4.1-2.1.el9.alma.x86_64  libgomp-11.4.1-2.1.el9.alma.x86_64 libstdc++-11.4.1-2.1.el9.alma.x86_64 libxml2-2.9.13-5.el9_3.x86_64       openssl-1:3.0.7-25.el9_3.x86_64          openssl-libs-1:3.0.7-25.el9_3.x86_64     zlib-1.2.11-40.el9.x86_64
Installed:
  autoconf-2.69-38.el9.noarch                      automake-1.16.2-8.el9.noarch                          binutils-2.35.2-42.el9.x86_64                       binutils-gold-2.35.2-42.el9.x86_64                   cmake-filesystem-3.20.2-9.el9_3.x86_64
  cpp-11.4.1-2.1.el9.alma.x86_64                   elfutils-debuginfod-client-0.189-3.el9.x86_64         emacs-filesystem-1:27.2-9.el9.noarch                fontconfig-2.14.0-2.el9_1.x86_64                     freetype-2.10.4-9.el9.x86_64
  fribidi-1.0.10-6.el9.2.x86_64                    gcc-11.4.1-2.1.el9.alma.x86_64                        gcc-c++-11.4.1-2.1.el9.alma.x86_64                  gd3php-2.3.3-9.el9.remi.x86_64                       gdk-pixbuf2-2.42.6-3.el9.x86_64
  glibc-devel-2.34-83.el9_3.7.x86_64               glibc-headers-2.34-83.el9_3.7.x86_64                  graphite2-1.3.14-9.el9.x86_64                       harfbuzz-2.7.4-8.el9.x86_64                          highway-1.0.7-1.el9.x86_64
  jbigkit-libs-2.1-23.el9.x86_64                   jxl-pixbuf-loader-0.7.0-1.el9.x86_64                  kernel-headers-5.14.0-362.18.1.el9_3.x86_64         keyutils-libs-devel-1.6.3-1.el9.x86_64               krb5-devel-1.21.1-1.el9.x86_64
  libX11-1.7.0-8.el9.x86_64                        libX11-common-1.7.0-8.el9.noarch                      libXau-1.0.9-8.el9.x86_64                           libXpm-3.5.13-8.el9_1.x86_64                         libaom-3.8.0-1.el9.x86_64
  libavif-0.11.1-4.el9.x86_64                      libcom_err-devel-1.46.5-3.el9.x86_64                  libdav1d-1.2.1-1.el9.x86_64                         libicu73-73.2-1.el9.remi.x86_64                      libimagequant-2.17.0-1.el9.x86_64
  libjpeg-turbo-2.0.90-6.el9_1.x86_64              libjxl-0.7.0-1.el9.x86_64                             libkadm5-1.21.1-1.el9.x86_64                        libmcrypt-2.5.8-30.el9.x86_64                        libmpc-1.2.1-4.el9.x86_64
  libpkgconf-1.7.3-10.el9.x86_64                   libpng-2:1.6.37-12.el9.x86_64                         libraqm-0.8.0-1.el9.x86_64                          libselinux-devel-3.5-1.el9.x86_64                    libsepol-devel-3.5-1.el9.x86_64
  libsodium-1.0.18-8.el9.x86_64                    libstdc++-devel-11.4.1-2.1.el9.alma.x86_64            libtiff-4.4.0-10.el9.x86_64                         libtool-2.4.6-45.el9.x86_64                          libverto-devel-0.3.2-3.el9.x86_64
  libvmaf-2.3.0-2.el9.x86_64                       libwebp-1.2.0-8.el9_3.x86_64                          libxcb-1.13.1-9.el9.x86_64                          libxcrypt-devel-4.4.18-3.el9.x86_64                  libxml2-devel-2.9.13-5.el9_3.x86_64
  m4-1.4.19-1.el9.x86_64                           make-1:4.3-7.el9.x86_64                               openssl-devel-1:3.0.7-25.el9_3.x86_64               pcre2-devel-10.40-2.el9.x86_64                       pcre2-utf16-10.40-2.el9.x86_64
  pcre2-utf32-10.40-2.el9.x86_64                   perl-AutoLoader-5.74-480.el9.noarch                   perl-B-1.80-480.el9.x86_64                          perl-Carp-1.50-460.el9.noarch                        perl-Class-Struct-0.66-480.el9.noarch
  perl-Data-Dumper-2.174-462.el9.x86_64            perl-Digest-1.19-4.el9.noarch                         perl-Digest-MD5-2.58-4.el9.x86_64                   perl-DynaLoader-1.47-480.el9.x86_64                  perl-Encode-4:3.08-462.el9.x86_64
  perl-Errno-1.30-480.el9.x86_64                   perl-Exporter-5.74-461.el9.noarch                     perl-Fcntl-1.13-480.el9.x86_64                      perl-File-Basename-2.85-480.el9.noarch               perl-File-Compare-1.100.600-480.el9.noarch
  perl-File-Copy-2.34-480.el9.noarch               perl-File-Find-1.37-480.el9.noarch                    perl-File-Path-2.18-4.el9.noarch                    perl-File-Temp-1:0.231.100-4.el9.noarch              perl-File-stat-1.09-480.el9.noarch
  perl-FileHandle-2.03-480.el9.noarch              perl-Getopt-Long-1:2.52-4.el9.noarch                  perl-Getopt-Std-1.12-480.el9.noarch                 perl-HTTP-Tiny-0.076-461.el9.noarch                  perl-IO-1.43-480.el9.x86_64
  perl-IO-Socket-IP-0.41-5.el9.noarch              perl-IO-Socket-SSL-2.073-1.el9.noarch                 perl-IPC-Open3-1.21-480.el9.noarch                  perl-MIME-Base64-3.16-4.el9.x86_64                   perl-Mozilla-CA-20200520-6.el9.noarch
  perl-NDBM_File-1.15-480.el9.x86_64               perl-Net-SSLeay-1.92-2.el9.x86_64                     perl-POSIX-1.94-480.el9.x86_64                      perl-PathTools-3.78-461.el9.x86_64                   perl-Pod-Escapes-1:1.07-460.el9.noarch
  perl-Pod-Perldoc-3.28.01-461.el9.noarch          perl-Pod-Simple-1:3.42-4.el9.noarch                   perl-Pod-Usage-4:2.01-4.el9.noarch                  perl-Scalar-List-Utils-4:1.56-461.el9.x86_64         perl-SelectSaver-1.02-480.el9.noarch
  perl-Socket-4:2.031-4.el9.x86_64                 perl-Storable-1:3.21-460.el9.x86_64                   perl-Symbol-1.08-480.el9.noarch                     perl-Term-ANSIColor-5.01-461.el9.noarch              perl-Term-Cap-1.17-460.el9.noarch
  perl-Text-ParseWords-3.30-460.el9.noarch         perl-Text-Tabs+Wrap-2013.0523-460.el9.noarch          perl-Thread-Queue-3.14-460.el9.noarch               perl-Time-Local-2:1.300-7.el9.noarch                 perl-URI-5.09-3.el9.noarch
  perl-base-2.27-480.el9.noarch                    perl-constant-1.33-461.el9.noarch                     perl-if-0.60.800-480.el9.noarch                     perl-interpreter-4:5.32.1-480.el9.x86_64             perl-libnet-3.13-4.el9.noarch
  perl-libs-4:5.32.1-480.el9.x86_64                perl-mro-1.23-480.el9.x86_64                          perl-overload-1.31-480.el9.noarch                   perl-overloading-0.02-480.el9.noarch                 perl-parent-1:0.238-460.el9.noarch
  perl-podlators-1:4.14-460.el9.noarch             perl-subs-1.03-480.el9.noarch                         perl-threads-1:2.25-460.el9.x86_64                  perl-threads-shared-1.61-460.el9.x86_64              perl-vars-1.05-480.el9.noarch
  php-7.4.33-10.el9.remi.x86_64                    php-devel-7.4.33-10.el9.remi.x86_64                   php-gd-7.4.33-10.el9.remi.x86_64                    php-intl-7.4.33-10.el9.remi.x86_64                   php-opcache-7.4.33-10.el9.remi.x86_64
  php-pdo-7.4.33-10.el9.remi.x86_64                php-pecl-mcrypt-1.0.7-1.el9.remi.7.4.x86_64           php-sodium-7.4.33-10.el9.remi.x86_64                pkgconf-1.7.3-10.el9.x86_64                          pkgconf-m4-1.7.3-10.el9.noarch
  pkgconf-pkg-config-1.7.3-10.el9.x86_64           rav1e-libs-0.7.1-1.el9.x86_64                         shared-mime-info-2.1-5.el9.x86_64                   svt-av1-libs-0.9.0-1.el9.x86_64                      tar-2:1.34-6.el9_1.x86_64
  xml-common-0.6.3-58.el9.noarch                   xz-devel-5.2.5-8.el9_0.x86_64                         zlib-devel-1.2.11-40.el9.x86_64

Complete!
[root@server webuser]# php -v
PHP 7.4.33 (cli) (built: Dec 12 2023 14:50:57) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies

php.ini の編集

バックアップをとっておく

[root@server webuser]# cp /etc/php.ini /etc/php.ini.default
post_max_size = 30M
upload_max_filesize = 20M
date.timezone = "Asia/Tokyo"
mbstring.language = Japanese
mbstring.internal_encoding = UTF-8
mbstring.http_input = UTF-8
mbstring.http_output = pass
mbstring.encoding_translation = On
mbstring.detect_order = auto
mbstring.substitute_character = none

composerのインストール

[root@server webuser]# curl -sS https://getcomposer.org/installer | php
All settings correct for using Composer
Downloading...

Composer (version 2.7.1) successfully installed to: /home/webuser/composer.phar
Use it: php composer.phar
[root@server webuser]# mv composer.phar /usr/local/bin/composer

MySQL5.7のインストール

MySQL5.7のインストール

[root@server webuser]# yum localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
Installed:
  mysql57-community-release-el7-7.noarch

Complete!
[root@server webuser]# yum info mysql-community-server
MySQL Connectors Community                                                                                                                                                                                                           754 kB/s |  68 kB     00:00
MySQL Tools Community                                                                                                                                                                                                                5.3 MB/s | 1.1 MB     00:00
MySQL 5.7 Community Server                                                                                                                                                                                                           8.0 MB/s | 3.1 MB     00:00
Available Packages
Name         : mysql-community-server
Version      : 5.7.44
Release      : 1.el7
Architecture : x86_64
Size         : 184 M
Source       : mysql-community-5.7.44-1.el7.src.rpm
Repository   : mysql57-community
Summary      : A very fast and reliable SQL database server
URL          : http://www.mysql.com/
License      : Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved. Under GPLv2 license as shown in the Description field.
Description  : The MySQL(TM) software delivers a very fast, multi-threaded, multi-user,
             : and robust SQL (Structured Query Language) database server. MySQL Server
             : is intended for mission-critical, heavy-load production systems as well
             : as for embedding into mass-deployed software. MySQL is a trademark of
             : Oracle and/or its affiliates
             :
             : The MySQL software has Dual Licensing, which means you can use the MySQL
             : software free of charge under the GNU General Public License
             : (http://www.gnu.org/licenses/). You can also purchase commercial MySQL
             : licenses from Oracle and/or its affiliates if you do not wish to be bound by the terms of
             : the GPL. See the chapter "Licensing and Support" in the manual for
             : further info.
             :
             : The MySQL web site (http://www.mysql.com/) provides the latest news and
             : information about the MySQL software.  Also please see the documentation
             : and the manual for more information.
             :
             : This package includes the MySQL server binary as well as related utilities
             : to run and administer a MySQL server.
[root@server webuser]# yum install -y mysql-community-server
Importing GPG key *****:
 Userid     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 Fingerprint: ****
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Key imported successfully
Import of key(s) didn't help, wrong key(s)?
Public key for mysql-community-client-5.7.44-1.el7.x86_64.rpm is not installed. Failing package is: mysql-community-client-5.7.44-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Public key for mysql-community-common-5.7.44-1.el7.x86_64.rpm is not installed. Failing package is: mysql-community-common-5.7.44-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Public key for mysql-community-libs-5.7.44-1.el7.x86_64.rpm is not installed. Failing package is: mysql-community-libs-5.7.44-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Public key for mysql-community-server-5.7.44-1.el7.x86_64.rpm is not installed. Failing package is: mysql-community-server-5.7.44-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'yum clean packages'.
Error: GPG check FAILED

GPGキーが間違っているとのこと。。
以下でGPGキーを更新して再度インストールをしたら行けた。

[root@server webuser]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

MySQLの起動と自動起動登録

[root@server webuser]# systemctl start mysqld
[root@server webuser]# systemctl enable mysqld

rootのパスワード設定

[root@server webuser]# cat /var/log/mysqld.log | grep root
[root@server webuser]# mysql -u root -p
mysql> set password  = password('xxxxxxx');
[root@server webuser]# systemctl restart mysqld

my.cnfの編集

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
character_set_server=utf8 ←追記
skip-character-set-client-handshake ←追記
sql_mode=NO_ENGINE_SUBSTITUTION ←追記
[root@server webuser]# systemctl restart mysqld

SSLの設定

mod_sslのインストール

[root@server webuser]# yum install mod_ssl
Installed:
  mod_ssl-1:2.4.57-5.el9.x86_64                                                                                                        sscg-3.0.0-7.el9.x86_64

Complete!

SSL証明書の設定

既存サーバーのconfファイルを確認

以降のサーバー証明書の場所やconfigファイルはサーバーごとに設定が異なるため、適宜確認する必要があります。

サーバー証明書の移行

既存サーバーの以下を新サーバーに設置する

SSLCertificateFile
SSLCertificateKeyFile
SSLCertificateChainFile

apacheにmod_ssl設定

[root@server certs]# vi /etc/httpd/conf.d/ssl.conf
SSLCertificateFile /etc/pki/tls/certs/server.crt
SSLCertificateKeyFile /etc/pki/tls/private/server.key
SSLCertificateChainFile /etc/pki/tls/certs/server-chain.crt
[root@server webuser]# systemctl restart httpd

Apacheの設定

DocumentRootの設定

既存サイトの設定を真似して色々調整する

[root@server webuser]# vi /etc/httpd/conf/httpd.conf
[root@server webuser]# systemctl restart httpd

ソースコードの移管

tarコマンドで圧縮して移管

現行サーバーのソースコード一式をtar.gzファイルに圧縮して、生成された html.tar.gz を移行先サーバーで展開します。

圧縮

[root@server html]# cd /var/www/html/
[root@server html]# tar cvzfp /home/webuser/html.tar.gz ./

解凍

[webuser@server html]$ cd /var/www/html/
[webuser@server html]$ tar xvzfp html.tar.gz

SELinuxの無効化

CakePHPだと、SELinuxが有効になっていると何かとエラーを吐くので、無効化しておきます。

[root@server html]# getenforce
Disabled
[root@server html]# setenforce 0
setenforce: SELinux is disabled

データベースの移管

phpMyAdminのインストール

とりあえず便利なので入れておきます。

エラー対応開始

WEB画面でアクセスしてみると、Service Unavailableとのこと。
エラーログは以下。
よくわからないけどパーミッション関連ぽい

[proxy:error] [pid 19092:tid 19146] (13)Permission denied: AH02454: FCGI: attempt to connect to Unix domain socket /run/php-fpm/www.sock (*:80) failed
[proxy_fcgi:error] [pid 19092:tid 19146] [client xxx.xxx.xxx.xxx:64497] AH01079: failed to make connection to backend: httpd-UDS

現状の確認

[root@server webuser]# systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
     Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; preset: disabled)
     Active: active (running) since Tue 2024-02-20 18:50:01 JST; 3h 44min ago
   Main PID: 20250 (php-fpm)
     Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec"
      Tasks: 6 (limit: 24831)
     Memory: 14.1M
        CPU: 541ms
     CGroup: /system.slice/php-fpm.service
             ├─20250 "php-fpm: master process (/etc/php-fpm.conf)"
             ├─20252 "php-fpm: pool www"
             ├─20253 "php-fpm: pool www"
             ├─20254 "php-fpm: pool www"
             ├─20255 "php-fpm: pool www"
             └─20256 "php-fpm: pool www"

パーミッション変更

[root@server webuser]# chown apache:apache /run/php-fpm/www.sock

解決せず。。

php-fpmの設定ファイル修正

[root@server webuser]# vi /etc/php-fpm.d/www.conf
user = webuser
group = webuser

listen = /run/php-fpm/www.sock

listen.owner = webuser
listen.group = webuser
listen.mode = 0660

;listen.acl_users = apache,nginx
;listen.acl_groups =
[root@server webuser]# systemctl restart php-fpm
[root@server webuser]# systemctl restart httpd

いけたいけた!

画面上に新しく発生したエラー

またパーミッション問題発生

Error during session start; please check your PHP and/or webserver log file and configure your PHP installation properly. Also ensure that cookies are enabled in your browser.

session_start(): open(SESSION_FILE, O_RDWR) failed: Permission denied (13)

session_start(): Failed to read session data: files (path: /var/lib/php/session)
[root@server webuser]# ls -la /var/lib/php/
drwxrwx---   2 root apache 4096 Dec 12 23:55 session
[root@server webuser]# chown webuser:webuser /var/lib/php/session
[root@server webuser]# ls -la /var/lib/php/
drwxrwx---   2 webuser webuser 4096 Dec 12 23:55 session

phpモジュール mysqlnd を入れる

[root@server webuser]# yum -y install php-mysqlnd
Installed:
  php-mysqlnd-7.4.33-10.el9.remi.x86_64

Complete!

正常にphpMyAdminが表示されれば完了!

データのバックアップ

以下を現行サーバーで実行。
Warning出たけどバックアップは出来たっぽい。

[webuser@server ~]$ mysqldump -uroot -ppassword database_name --hex-blob > 20240221_database_name.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.

データのリストア

[webuser@server ~]$ mysql -uroot -ppassword database_name < 20240221_database_name.sql
mysql: [Warning] Using a password on the command line interface can be insecure.

これもWarningできたけど問題なさそう。
phpMyAdminで確認して、正常にデータが入っていればリストア完了。

終わり

以上で、移管作業が完了しました。
サイトを画面確認して、問題無いことをチェック。

あとは、cronとかの設定をしている場合は、その設定とかも移行しないとだね。

[webuser@server ~]$ crontab -l

コメント