WordPressをAWSLightSailへ切り替えて、無料SSL証明書の設定し、月5ドルで運用
![aws-lightsail](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/aws-lightsail.jpg?resize=1280%2C720&ssl=1)
このブログは、AWSLightSailを使って毎月5ドルのプランでWordPressを動かしています。
今回は、古いAWSLightSailで動いていたインスタンスを削除し、新しいAWSLightSailのインスタンスへ切り替える手順を記載します。
![o_wani](https://i0.wp.com/owani.net/wp-content/uploads/2023/11/DALL·E-2023-06-09-16.00.49-High-quality-photo-of-a-Shiba-Inu-astronaut.jpg?resize=72%2C72&ssl=1)
WordPressの格安サーバーって結構いろいろありますね。XserverやConoHaなど私もいろいろ使ってきました。その中で今回は、AWSという選択を提案したいと思います。
プランは毎月5ドルで「1 GB RAM、2 vCPU、40 GB の SSD」です。
加えてSSL証明書は無料で利用できますので、結構コストパフォーマンスが良いのではないでしょうか?かなりの低コストでいけるので、当ブログでも数年間愛用しています。
![](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-101.png?resize=1024%2C328&ssl=1)
他のサービスからAWSLightSailへ切り替え(引っ越し)たい人も参考になる記事になると思います。
AWSLightSailはroot権限もあるので、SSHで接続して、サーバーの再起動なども自由にできますね。
Amazon Web Services (AWS)が提供するシンプルで手軽なクラウドプラットフォームです。これは、小規模ビジネス、開発者、学生などのユーザーに向けて、アプリケーションやウェブサイトを簡単にデプロイし、管理するための仮想プライベートサーバー(VPS)を提供します。
主な特徴には以下のようなものがあります:
- 簡単なセットアップ: ユーザーは数クリックでサーバーをセットアップし、アプリケーションのデプロイを開始できます。
- 固定料金: 月額固定料金で、予測可能なコスト管理が可能です。
- スケーラビリティ: ビジネスやアプリケーションの成長に応じて、リソースを簡単にスケールアップ・ダウンできます。
- 管理とメンテナンス: サーバーのメンテナンスや管理がAWSによって簡素化されています。
- AWSのインフラストラクチャ: LightsailはAWSの広範なインフラストラクチャと統合されており、AWSの他のサービスと連携して使用することができます。
- セキュリティと信頼性: AWSのセキュリティと信頼性の高いインフラストラクチャを利用することで、データの保護が図られます。
Amazon Lightsailは、複雑な構成やコストの心配を減らし、特に小規模なプロジェクトや予算に限りがあるプロジェクトに適した選択肢となっています。
今回は月5ドルのプランでいきますが、相当のスペックまで利用できます。
![](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-102.png?resize=1024%2C231&ssl=1)
2023 年 6 月 29 日以前に作成された仮想サーバーは、同じプランでも1 vCPU が搭載されています。新しいプランでは、2 vCPU ですので、パフォーマンスも良くなりました。
![](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-103.png?resize=1024%2C304&ssl=1)
まずは、こちらを参考に進めます。
![見習い](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/よこやん.png?resize=72%2C72&ssl=1)
今回は主に4つの手順があります。新環境を構築したあと、記事データ移行などを行ったあとに、ドメイン付与とHTTPS化します。
- AmazonLightsailでWordPressの構築
- データ移行
- 独自ドメイン切り替え
- SSL証明書の対応(HTTPS化)
ですね。
インスタンスの新規作成
a.[インスタンスの作成]をクリックします。
![インスタンスの作成](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-104.png?resize=1024%2C356&ssl=1)
b.インスタンスロケーションを選択します。
![インスタンスロケーション](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-105.png?resize=1024%2C282&ssl=1)
※変更する場合は[AWS リージョンとアベイラビリティーゾーンの変更]を選択しますが、今回は変更しませんので、そのままで進めます。
c.インスタンスイメージを選択します。
- プラットフォームでは[Linux/Unix]を選択する。
- 設計図の選択では[WordPress]を選択する。
![インスタンスイメージの選択](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-106.jpg?resize=1024%2C847&ssl=1)
d.インスタンスプランを選択します。
今回は5 USDのプランを選択します。
![インスタンスプランの選択](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-106.png?resize=1024%2C490&ssl=1)
e.インスタンス名を入力し、[インスタンスの作成]をクリックします。
![](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-107.png?resize=1024%2C589&ssl=1)
作成後は一覧に遷移し、「保留中」となります。
![インスタンス一覧](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-109.png?resize=1024%2C406&ssl=1)
「実行中」にステータスが変更になるので、[管理]をクリックします。
![](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-110.png?resize=980%2C464&ssl=1)
接続情報が表示されるので、[デフォルトキーのダウンロード]をクリックしてSSH接続のためのKEYをダウンロードしておきます。
![](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-111.jpg?resize=1024%2C903&ssl=1)
ダウンロードしたKEYは後ほど使います。
ブラウザでSSH接続し、WordPressのログインPWを入手
作成したWordPressの環境の管理画面にログインする情報(パスワード)を入手するためにSSH接続する必要があります。
a.[SSHを使用して接続]をクリックします。
![](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-111.png?resize=1024%2C508&ssl=1)
b.SSH クライアントウィンドウが開いたら、次のコマンドを入力してデフォルトのWordPressログイン用パスワードを取得します。
$ cat $HOME/bitnami_application_password
![](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-112.jpg?resize=1024%2C434&ssl=1)
このコマンド表示されるパスワードは保存しておき、WordPressのログインで利用します。
ブラウザでWordPressの管理画面にログイン
ドメインはまだ割り当てられていないのでパブリックIPアドレスでアクセスします。
a.ブラウザでパブリックIPアドレス(XXX.XXX.XXX.XXX)にアクセスします。
http://XXX.XXX.XXX.XXX/wp-login.php
パブリックIPアドレスは、インスタンスのホーム画面で取得できます。
![](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-112.png?resize=1024%2C433&ssl=1)
b.WordPressの管理画面にログインします。
- [ユーザー名] または [メールアドレス] ボックスに「user」と入力する。
- [パスワード] ボックスに、このチュートリアルの前半で取得したWordPressログイン用パスワードを入力する。
- [ログイン]をクリックする。
c.WordPressの管理画面にログインが成功します。
![](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-113.jpg?resize=1024%2C428&ssl=1)
静的IP(Static IP)アドレスを付与する
a.インスタンス名をクリックして、ネットワーキング情報を表示します。
[静的IPをアタッチする]をクリックします。
![](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-113.png?resize=1024%2C549&ssl=1)
b.LightSailのリソース名を指定します。
- LightSailのリソース名を入力する。
- [作成およびアタッチ]をクリックする。
![](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-114.png?resize=1018%2C684&ssl=1)
c.静的IPの作成が完了しました。
無事作成されるので、[続行する]をクリックします。
![](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-115.png?resize=980%2C322&ssl=1)
データの移行を実施する
今回は、All-in-One WP Migrationを使ってみます。とても優秀なツールでした。
![All-in-One WP Migration](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-116.png?resize=1024%2C438&ssl=1)
a.インポート側の最大サイズを確認します。
インポートの最大サイズが80MBになっています。
![インポートサイズ変更前](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-117.png?resize=1024%2C420&ssl=1)
b.インポート側の最大サイズを520MB(適当)に変更します。
今回私がエクスポートしたデータは全部で320MBでした。(※エクスポートは同様のツールを使ってエクスポートします)
それをインポートするために80MBから520MBに変更しました。
- SSH接続する。
- PHPの設定ファイルを編集する。
$ sudo vi /opt/bitnami/php/etc/php.ini
変更する項目は、下記に記載します。
upload_max_filesize = 520M
post_max_size = 520M
memory_limit = 520M
max_execution_time = 300
max_input_time = 300
上記に変更して保存します。
- WEBサーバー再起動する。
$ sudo /opt/bitnami/ctlscript.sh restart
Restarting services..
画面にアクセスすると、520MBに変わっていることを確認できました。
![インポートサイズ変更完了](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-118.png?resize=1024%2C443&ssl=1)
c.インポートを実施します。
エクスポートしたファイルをドラッグアンドドロップします。
![インポート実施](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-119.png?resize=1024%2C467&ssl=1)
データをエクスポートしたインスタンスのPHPが古く、今回新規作成したインスタンスはPHP8のため怒られている。構わず、[PROCEED>]をクリックする。
![PHPのバージョンに対する警告](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-120.png?resize=1024%2C555&ssl=1)
インポートが処理されていきます。
![リストア](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-121.png?resize=1024%2C393&ssl=1)
インポートが成功しました。
![サイトインポート](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-122.png?resize=1024%2C437&ssl=1)
LightSailでDNSゾーンを作成する
a.サイドメニューの「ドメインとDNS」を表示します。
![DNSゾーンの作成](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-123.jpg?resize=1024%2C505&ssl=1)
b.[DNSゾーンの作成]をクリックします。
- ドメインのソース:別のレジストラからドメインを使用
- 私の場合は、お名前.comなので別のレジストラです。
- ドメイン名:owani.net(私の場合)
![DNSゾーンの作成](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-123-1.jpg?resize=1009%2C1024&ssl=1)
c.DNSゾーンの作成が完了しました。
![DNSゾーンの作成が完了](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-123.png?resize=1024%2C714&ssl=1)
d.お名前.comでネームサーバー変更します。
![ネームサーバー](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-124.png?resize=673%2C777&ssl=1)
設定完了です。
![ネームサーバーの変更完了](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-125.png?resize=659%2C635&ssl=1)
独自ドメインの切り替えとSSL証明書を発行
新しいインスタンスのAレコードを登録します。
a.DNSレコードのAレコードの設定を行います。
![DNSレコード](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/image-126.jpg?resize=1024%2C651&ssl=1)
b.Let’sEncryptでSSL証明書の発行をします。
ロードバランサーを使用したかったですが、コストかかりますので、定番の無料SSL証明書「Let’sEncrypt」を設定します。
$ sudo /opt/bitnami/bncert-tool
----------------------------------------------------------------------------
Welcome to the Bitnami HTTPS Configuration tool.
----------------------------------------------------------------------------
Domains
Please provide a valid space-separated list of domains for which you wish to
configure your web server.
Domain list []: owani.net
The following domains were not included: www.owani.net. Do you want to add them? [Y/n]: n
Warning: No www domains (e.g. www.example.com) or non-www domains (e.g.
www.example.com) have been provided, so the following redirections will be
disabled: non-www to www, www to non-www.
Press [Enter] to continue:
----------------------------------------------------------------------------
Enable/disable redirections
Please select the redirections you wish to enable or disable on your Bitnami
installation.
Enable HTTP to HTTPS redirection [Y/n]: Y
----------------------------------------------------------------------------
Changes to perform
The following changes will be performed to your Bitnami installation:
1. Stop web server
2. Configure web server to use a free Let's Encrypt certificate for the domains:
owani.net
3. Configure a cron job to automatically renew the certificate each month
4. Configure web server name to: owani.net
5. Enable HTTP to HTTPS redirection (example: redirect http://owani.net to
https://owani.net)
6. Start web server once all changes have been performed
Do you agree to these changes? [Y/n]: Y
----------------------------------------------------------------------------
Create a free HTTPS certificate with Let's Encrypt
Please provide a valid e-mail address for which to associate your Let's Encrypt
certificate.
Domain list: owani.net
Server name: owani.net
E-mail address []: info@owani.net
The Let's Encrypt Subscriber Agreement can be found at:
https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf
Do you agree to the Let's Encrypt Subscriber Agreement? [Y/n]: Y
----------------------------------------------------------------------------
Performing changes to your installation
The Bitnami HTTPS Configuration Tool will perform any necessary actions to your
Bitnami installation. This may take some time, please be patient.
----------------------------------------------------------------------------
Success
The Bitnami HTTPS Configuration Tool succeeded in modifying your installation.
The configuration report is shown below.
Backup files:
* /opt/bitnami/apache/conf/httpd.conf.back.202311271526
* /opt/bitnami/apache/conf/bitnami/bitnami.conf.back.202311271526
* /opt/bitnami/apache/conf/bitnami/bitnami-ssl.conf.back.202311271526
* /opt/bitnami/apache/conf/vhosts/wordpress-https-vhost.conf.back.202311271526
* /opt/bitnami/apache/conf/vhosts/wordpress-vhost.conf.back.202311271526
Find more details in the log file:
/tmp/bncert-202311271526.log
If you find any issues, please check Bitnami Support forums at:
https://github.com/bitnami/vms
Press [Enter] to continue:
![見習い](https://i0.wp.com/owani.net/wp-content/uploads/2023/12/よこやん.png?resize=72%2C72&ssl=1)
完了ですね?
![o_wani](https://i0.wp.com/owani.net/wp-content/uploads/2023/11/DALL·E-2023-06-09-16.00.49-High-quality-photo-of-a-Shiba-Inu-astronaut.jpg?resize=72%2C72&ssl=1)
はい!
いつかロードバランサーを使用したパターンも試したいです。