1
1

More than 1 year has passed since last update.

Mautic 2.x から 4 まで一気にアップデート

Last updated at Posted at 2022-01-04

専用やクラウドサーバーで直接行う場合は sudo -u apache or sudo -u nginx など、ウェブサーバーのユーザーとして sudo する必要がある場合があるかもなので、Mautic や php コマンドを実行する際はお気をつけください。

Mautic 2.x の最新版にアップデート

Release ページから 2.16.3 の 2.16.3-update.zip をダウンロード
https://github.com/mautic/mautic/releases/tag/2.16.3

(オプション) サーバー上にアップロードして展開する場合

一旦、展開してフォルダのない状態で再圧縮。

unzip 2.16.3-update.zip
cd 2.16.3-update
zip -r 2.16.3-update_nofolder.zip * .*

サーバー or ローカルのテストサーバー上で zip を展開
.htaccess ファイルなど、コアファイル変更している場合は差分の修正に注意。

2.16.3 には、Mautic V3 にアップデートできるスクリプトが入っています。

unzip 2.16.3-update_nofolder.zip

アップデート実行

Mautic の 2.16.3 をアップデート。
同梱の upgrade.php ファイルを使ってアップデート

php upgrade.php

Mautic を v3 にアップデート

php upgrade_v3.php

GitHub からパッケージをダウンロードした場合、以下のような Warning がでてアップグレード前にストップします。

One or more warnings occurred during pre-upgrade checks, please run this script with the --ignore-warnings flag to continue: 
- You seem to have installed Mautic by cloning from GitHub. We don't support upgrading with the upgrade script in this scenario. Proceed at your own risk or reinstall with the official package at <a target="_blank" href="https://github.com/mautic/mautic/releases/tag/2.16.3">https://github.com/mautic/mautic/releases/tag/2.16.3</a>

GitHub からソフトをダウンロードした心当たりがある人で、前述と全く同じ Warning が出て中断してしまった 場合のみ --ignore-warnings オプションをつけて実行します。

php upgrade_v3.php --ignore-warnings

Composer の変更のため、もう一度、アップグレードスクリプトを起動する必要があります。

php upgrade_v3.php

すべてうまくいくと

Do you want to remove the backup files? We recommend first checking in a browser whether Mautic 3 works as expected. Type "yes" to remove:

とアップグレードスクリプトがとってくれたバックアップしたデータベースdumpを削除するか聞いてきます。僕はアップグレード開始前にそもそもバックアップをとっていたので不要です。なので yes と答えて削除します。

僕のアップグレードのログは以下のようになりました。

% php upgrade_v3.php --ignore-warnings
Welcome to the Mautic 3 upgrade script! Before we start, we'll run some pre-upgrade checks to make sure your system is compatible.
IMPORTANT: you will need to update your cron jobs from app/console/* to bin/console/* after the upgrade. You can already change them now if you want.
Please type 'yes' if you're ready to start: yes

Thank you, continuing...
===== STARTING MAUTIC 3 UPGRADE AT 2022-01-04 08:03:40... =====
Installed Mautic version:	2.16.5
PHP version:				7.3.30
OS:							Darwin
Upgrade type:				CLI

Doing pre-upgrade checks...
One or more warnings occurred during pre-upgrade checks, please run this script with the --ignore-warnings flag to continue: 
- You seem to have installed Mautic by cloning from GitHub. We don't support upgrading with the upgrade script in this scenario. Proceed at your own risk or reinstall with the official package at <a target="_blank" href="https://github.com/mautic/mautic/releases/tag/2.16.3">https://github.com/mautic/mautic/releases/tag/2.16.3</a>
Finished pre-upgrade checks.
Starting upgrade...
Backing up your database...
Database backup successfully written to your Mautic root folder.
Getting the amount of available Mautic 2 database migrations... This might take a while!
No available database migrations found. On to the next step...
Downloading Mautic 3...
Extracting the update package...
Extracting done!
Preparing for phase 2 of the upgrade...
IMPORTANT: NOT DONE YET! Due to the large amount of changes in Composer dependencies, we now need to restart the script to continue. We've saved your state, so we'll continue where we left off.
PLEASE RUN php upgrade_v3.php AGAIN TO START PHASE 2 OF THE UPGRADE!
katz@Eden git.mautic % php upgrade_v3.php --ignore-warnings
Welcome to Phase 2 of the Mautic 3 upgrade! We'll continue where we left off.
Moving Mautic 2 files into mautic-2-backup and moving the Mautic 3 files in place, this might take a while... DO NOT ABORT THE SCRIPT!!!
Done!

Updating your config/local.php with new settings that were changed/introduced in Mautic 3...
Done! Your config file has been updated.
Getting the amount of available Mautic 3 database migrations... This might take a while!
Applying Mautic 3 database migrations, 14 migrations in total... This might take a while!
All Mautic 3 migrations applied successfully.
Restoring your user data like custom plugins/themes/media from the Mautic 2 installation. This might take a while... DO NOT ABORT THE SCRIPT!!!
Done! Your user data has been restored. Your Mautic 3 installation is ready. Just one more thing:
Cleaning up installation files that we no longer need...
Cleaned up successfully!
Building cache for Mautic 3...
Done! Cache has been built.
We're done! Enjoy using Mautic 3 :)
Don't forget to update your cron jobs!
Do you want to remove the backup files? We recommend first checking in a browser whether Mautic 3 works as expected. Type "yes" to remove:
yes

Thank you, continuing...
Backup files successfully removed, as well as the current upgrade script. Enjoy Mautic 3!

インストール中のメッセージにも出ていましたが、CLI の実行方法が app/console から bin/console 方式に変わったので、Cron など必要な設定をアップデートしておきましょう。

Mautic 3 の最新版にアップデート

現在の状態をバックアップします。

DB を mysqldump

cd [バックアップ保存先]
mysqldump -h [DBホスト名] -u [DBユーザー] --password="[DBパスワード]" --single-transaction --no-tablespaces [DB名前] | gzip > mautic_v3.2.4_$(date +%Y%m%d%H%M%S).sql.gz

Mautic 3.2.4 をバックアップ

tar -cvzf mautic_v3.2.4_$(date +%Y%m%d%H%M%S).tar.gz -C [Mautic ルート] [Mautic ルート]

PHP を 7.4 に変更

Mautic 4 では、PHP 7.4 しか対応していません。
PHP 7.4 は Mautic 3.2.X 以降で対応しています。
さきほどの手順で Mautic 3.2.4 にアップデートできたので、
使用している環境を PHP 7.4 に変更しましょう。

僕の場合は、手順が煩雑になったため、以下のように作業しています。

  • 旧環境は旧サーバーで温存
  • 新しい別の環境で PHP7.4 のサーバーを構築
  • ファイル・データベースはローカルにダウンロードして、アップグレードしながらローカルの PHP バージョンを 7.3 -> 7.4 に変更
  • ローカルでの作業完了後、ファイルをアップロード

つまりこの作業を行なっている間、Mautic でデータが入らなくなるため、トラフィックの少ない時間帯や、リード情報の差分を更新するなどの対応が必要です。

Mautic 3 の状態を一旦バックアップ

2022/1/4 時点で 3.2.4 にアップデートされたので、コマンドでは 3.2.4 と書いています。

# DB を mysqldump
cd [バックアップ保存先]
mysqldump -h [DBホスト名] -u [DBユーザー] --password="[DBパスワード]" --single-transaction --notablespaces [DB名前] | gzip > mautic_v3.2.4_$(date +%Y%m%d%H%M%S).sql.gz
# Mautic 3.2.4 をバックアップ
tar -cvzf mautic_v3.2.4_$(date +%Y%m%d%H%M%S).tar.gz -C [Mautic ルート] [Mautic ルート]

Mautic 3 のアップデートチェック

cd [Mautic ルート]
php bin/console mautic:update:find

3.3.4 にアップデート可能というメッセージがでます。

 % php bin/console mautic:update:find
Version 3.3.4 of Mautic is available for download. Please visit https://github.com/mautic/mautic/releases/tag/2.15.1 for more information.
To update, you can run 'php bin/console mautic:update:apply' from the command line.

Mautic 3.3.4 にアップデート

% php bin/console mautic:update:apply

Are you sure? と聞いてくるので y と返答してアップデート開始。

% php bin/console mautic:update:find
Version 3.3.4 of Mautic is available for download. Please visit https://github.com/mautic/mautic/releases/tag/3.3.4 for more information.
To update, you can run 'php bin/console mautic:update:apply' from the command line.
katz@Eden git.mautic % php bin/console mautic:update:apply
Are you sure you wish to update Mautic to the latest version? y
Step    5 [----->----------------------] Clearing the cache

<warning>IMPORTANT: Run the same command again with --finish. For example 'php bin/console mautic:update:apply --finish'</warning>

とメッセージが出たので、メッセージの忠告通り

php bin/console mautic:update:apply --finish

を実行します。

(出たメッセージに応じて対応が必要です)

% php bin/console mautic:update:apply --finish

Step    1 [->--------------------------] Migrating database schema...  
Step    2 [============================] Success! You are now running version 3.3.4 of Mautic.

3.3.4 にアップデートできました。

バックアップ

4.x.x にアップグレードする前に、途中の経過をバックアップしておきます。

## DB を mysqldump
cd [バックアップ保存先]
mysqldump -h [DBホスト名] -u [DBユーザー] --password="[DBパスワード]" --single-transaction --notablespaces [DB名前] | gzip > mautic_v2.16.5_$(date +%Y%m%d%H%M%S).sql.gz

## ファイルのバックアップ

tar -cvzf mautic_v2.16.5_$(date +%Y%m%d%H%M%S).tar.gz -C [Mautic ルート] [Mautic ルート]

Mautic 4 にアップデート

Mautic 4 アップデートのチェック

cd [Mautic ルート]
php bin/console mautic:update:find

4.1.1 にアップデート可能という表示が出ます。

% php bin/console mautic:update:find                       
Version 4.1.1 of Mautic is available for download. Please visit https://github.com/mautic/mautic/releases/tag/4.1.1 for more information.
To update, you can run 'php bin/console mautic:update:apply' from the command line.

Mautic 4 アップデートの実行

php bin/console mautic:update:apply

今までと同じく、データベーススキーマ変更をするために「--finish」をつけてもう一回実行

php bin/console mautic:update:apply --finish

しかし、僕の場合は、なぜかエラーがでたので、もう一度、 mautic:update:apply --finish を実行したら完了しました。

実際のログは以下の通りです。

% php bin/console mautic:update:find                       
Version 4.1.1 of Mautic is available for download. Please visit https://github.com/mautic/mautic/releases/tag/4.1.1 for more information.
To update, you can run 'php bin/console mautic:update:apply' from the command line.
% php bin/console mautic:update:apply

Are you sure you wish to update Mautic to the latest version? y
Step    6 [------>---------------------] Clearing the cache

<warning>IMPORTANT: Run the same command again with --finish. For example 'php bin/console mautic:update:apply --finish'</warning>
katz@Eden git.mautic % php bin/console mautic:update:apply --finish
Step    1 [>---------------------------] Migrating database schema...

An error occurred while updating the database. Check log for more details.
% php bin/console mautic:update:apply --finish
Step    2 [============================] Success! You are now running version 4.1.1 of Mautic.

これで、無事、Mautic を V4 にアップデートできました。

[オプション] 公開作業

僕の場合は、この作業をローカルで行なったので、この後は

  • app/config/local.php の値を新サーバーに変更
  • ローカルのファイル・DBをバックアップ
  • ファイル・DB を、新サーバーにインポート
  • DNS レコードを変更して新サーバーに向きを変える

作業を行いました。

バグ見つけた:ライブラリのフォルダ名の大文字ミス

本番サーバーにデータを移行したときにはまったメモ。
MacOS のローカルで成功したアップデートを Amazon Linux 2 な AWS 本番サーバーに戻した時、以下の PHP fetal error でハマってしまいました。

PHP Warning:  require(/var/www/vhosts/example/vendor/composer/../markbaker/matrix/classes/src/Functions/adjoint.php): failed to open stream: No such file or directory in /var/www/vhosts/example/vendor/composer/autoload_real.php on line 71
PHP Fatal error:  require(): Failed opening required '/var/www/vhosts/example/vendor/composer/../markbaker/matrix/classes/src/Functions/adjoint.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/vhosts/example/vendor/composer/autoload_real.php on line 71

とか

HP Warning:  require(/var/www/vhosts/example/vendor/composer/../markbaker/matrix/classes/src/Operations/add.php): failed to open stream: No such file or directory in /var/www/vhosts/example/vendor/composer/autoload_real.php on line 71
PHP Fatal error:  require(): Failed opening required '/var/www/vhosts/example/vendor/composer/../markbaker/matrix/classes/src/Operations/add.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/vhosts/example/vendor/composer/autoload_real.php on line 71

みたいなエラーに遭遇。

フォルダ名の最初の文字が大文字じゃないといけないのに実際は小文字だったのが原因だった。

/vendor/markbaker/matrix/classes/src/functions

functions フォルダを Functions に名前変更し

/vendor//markbaker/matrix/classes/src/operations

operations フォルダを Operations に名前変更すると
エラーが出なくなった。

GitHub に Issue 登録した

1
1
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
1
1