Amazon Lightsailで非アクティブな設計図を使ってみた

2022.05.31

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

いわさです。

Lightsailでは設計図(blueprint)を使ってデフォルトのアプリケーションスタックをデプロイしています。
マネジメントコンソールでは最新の設計図のみ利用出来ますが、実はAWS CLIからだと古い設計図も利用が出来ます。

本日はこちらを試してみましたので紹介します。

経緯

Lightsail で WordPress を使っていたら、いつのまにか PHP のバージョンが 8.0 になっていることに気がつきました。

Linux ip-172-26-0-49 4.19.0-20-cloud-amd64 #1 SMP Debian 4.19.235-1 (2022-03-17) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
       ___ _ _                   _
      | _ |_) |_ _ _  __ _ _ __ (_)
      | _ \ |  _| ' \/ _` | '  \| |
      |___/_|\__|_|_|\__,_|_|_|_|_|

  *** Welcome to the WordPress packaged by Bitnami 5.9.3-8         ***
  *** Documentation:  https://docs.bitnami.com/aws/apps/wordpress/ ***
  ***                 https://docs.bitnami.com/aws/                ***
  *** Bitnami Forums: https://community.bitnami.com/               ***
bitnami@ip-172-26-0-49:~$ php -v
PHP 8.0.17 (cli) (built: Apr 13 2022 15:26:22) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.17, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.17, Copyright (c), by Zend Technologies

Lightsail の WordPress では WordPress がパッケージされた Bitnami を使っています。
Lightsail 最新の WordPress 設計図から作成されるバージョンは5.9.3です。

最近の Bitnami WordPress の更新履歴を見てみましょう。

https://bitnami.com/stack/wordpress/installer/changelog.txt

Version 5.9.3-1      2022-05-17
* Maintenance release
* Updated OpenSSL to 1.1.1o
* Updated PHP to 8.0.19
* Updated phpMyAdmin to 5.2.0
* Updated SQLite to 3.38.5

Version 5.9.3-0      2022-04-06
* Updated Apache to 2.4.53
* Updated MariaDB to 10.4.24
* Updated OpenSSL to 1.1.1n
* Updated PHP to 8.0.17
* Updated SQLite to 3.38.2
* Updated WordPress to 5.9.3

Version 5.9.2-0     2022-03-15
* Updated PHP to 7.4.28
* Updated SQLite to 3.38.0
* Updated WordPress to 5.9.2
:

どうやら、2022-04-06 の Version 5.9.3 以降、PHP 7.4 から PHP 8.0 になったようです。むむ。

BitnamiのPHPバージョンは変更できるのか

BitnamiのPHPはパッケージマネージャーなどからインストールされたものではなくて、Bitnamiが独自にセットアップしたPHPを利用しています。

bitnami@ip-172-26-0-49:~$ which php
/opt/bitnami/php/bin/php
bitnami@ip-172-26-0-49:~$ ls -l /opt/bitnami/php/bin/php
-rwxr-xr-x 1 root root 21033584 Apr 13 15:28 /opt/bitnami/php/bin/php

モジュールパスの問題なので、頑張ればどうにか出来そうな気もしますが、BitnamiとしてはPHPバージョンのダウングレードはサポートされていないとのこと。

方法としてはLightsailでDebianサーバーを作成し、手動でBitnamiをインストールする方法が紹介されています。
この方法は次回試したいと思いますが、今回はもうちょっと簡単に出来ないものかということで、前まで利用出来ていたLightsail設計図を使う方法を探しました。

非アクティブな Lightsail設計図を利用する

Lightsailのコンソール画面ではアクティブなバージョンの設計図のみが表示されます。
しかし、AWS CLIでは非アクティブな設計図の情報を取得し、その情報を使ってLightsailインスタンスを作成することが出来ます。

注意点があって、非アクティブな設計書は既存インスタンスをサポートするために用意されているものであり、必ず利用できることが保証されているものではありません。また、古いOSやアプリケーションバージョンなのでセキュリティリスクを含んでいることもあります。
原則として、アクティブな設計図を使うべきという認識が必要です。

Use active blueprints when creating new instances. Inactive blueprints are listed to support customers with existing instances and are not necessarily available to create new instances. Blueprints are marked inactive when they become outdated due to operating system updates or new application releases.

設計図を調べる

上述のget-blueprintsコマンドでinclude-inactiveオプションを使うと非アクティブな設計図も抽出できるようになります。
以下は非アクティブな設計図を含む形でwordpressグループで検索した設計図IDの一覧です。

$ aws lightsail get-blueprints --include-inactive --query 'blueprints[?group == `wordpress`].blueprintId'
[
    "wordpress_4_6_1",
    "wordpress_4_7_2",
    "wordpress_4_7_3",
    "wordpress_4_7_5",
    "wordpress_4_8_0",
    "wordpress_4_8_1",
    "wordpress_4_9_2_1",
    "wordpress_4_9_4_5",
    "wordpress_4_9_6",
    "wordpress_4_9_8",
    "wordpress_5_0_3_2",
    "wordpress_5_1_1_2",
    "wordpress"
]

wordpressが最新を指しています。
ここでは、ひとつ前のバージョンのwordpress_5_1_1_2を使ってみましょうか。
ただ、最新の5.9.3からずいぶん間があいてますね。
Bitnami WordPress更新履歴で確認してみると、構成は以下です。

Version 5.1.1-2      2019-04-30
* Maintenance release
* Updated lego to 2.5.0
* Updated MySQL to 8.0.16
* Updated PHP to 7.2.17
* Updated SQLite to 3.28.0
* Updated Varnish to 6.0.3
* Updated WP-CLI to 2.2.0

3年前でPHP 7.2ですね。
古すぎる気もしますが、利用できるものがこれしかなさそうなので使ってみましょう。

非アクティブな設計図を使ってLightsailインスタンスを作成

インスタンス作成は、create-instancesを利用します。
パラメータとして、先程の設計図IDが必要です。

$ aws lightsail create-instances --instance-names "WordPressHoge" --availability-zone ap-northeast-1a --blueprint-id wordpress_5_1_1_2 --bundle-id nano_2_0
{
    "operations": [
        {
            "id": "458fc8f9-b954-4ffa-83a0-b091c82ae112",
            "resourceName": "WordPressHoge",
            "resourceType": "Instance",
            "createdAt": "2022-05-30T15:25:56.525000+09:00",
            "location": {
                "availabilityZone": "ap-northeast-1a",
                "regionName": "ap-northeast-1"
            },
            "isTerminal": false,
            "operationType": "CreateInstance",
            "status": "Started",
            "statusChangedAt": "2022-05-30T15:25:56.525000+09:00"
        }
    ]
}

こんにちは!

作成出来ていそうですね。
SSHでアクセスしてみましょう。

Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.4.0-1081-aws x86_64)
       ___ _ _                   _
      | _ |_) |_ _ _  __ _ _ __ (_)
      | _ \ |  _| ' \/ _` | '  \| |
      |___/_|\__|_|_|\__,_|_|_|_|_|

  *** Welcome to the Bitnami WordPress 5.1.1-2 ***
  *** Documentation:  https://docs.bitnami.com/aws/apps/wordpress/ ***
  ***                 https://docs.bitnami.com/aws/ ***
  *** Bitnami Forums: https://community.bitnami.com/ ***
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

bitnami@ip-172-26-9-179:~$ php -v
PHP 7.2.17 (cli) (built: Apr 29 2019 08:23:51) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.17, Copyright (c) 1999-2018, by Zend Technologies

やはりだいぶ古いですね。

さいごに

以前はPHPの7.3や7.4のWordPressインスタンスが存在していたと記憶しているので、どうやら全ての古い設計図が利用できるわけではなさそうです。

PHP8.0だと互換がなくて7.4でWordPressを動かしたいというユースケースがありそうなので、そういった場合はこの方法では難しそうですね。
別の方法でBitnami WordPressのPHPバージョンを変更する方法を探りたいと思います。

とはいえ、最新以外の設計図でインスタンス作成することもできるという点は確認することが出来たので、選択肢として覚えておいても良いのかなと思います。