LightsailのLAMP環境で常時SSL化


はじめに

LightsailのLAMPブループリントを使ったインスタンスを常時SSL化したく、
certbotのインストール手順を参考にしつつ、作業していたのですが
certbotを動かす段階で以下のようなエラーに遭遇しました。


Error while running apache2ctl graceful.
httpd not running, trying to start
Action 'graceful' failed.
The Apache error log may have more information.

AH00558: apache2: Could not reliably determine the server's fully qualified domain 
name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this mes
sage
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:8
0
no listening sockets available, shutting down
AH00015: Unable to open logs

もう少し探せばきちんとした解決策があるのかもしれませんが、
私が調べた限りの情報を共有できればと考えております。

解決策

bitnamiのドキュメントによると、
let's Encryptを使うためのツールが準備されているようです。
https://docs.bitnami.com/aws/infrastructure/lamp/administration/generate-configure-certificate-letsencrypt/

ただ、LightsailのLAMPには同梱されていないように見受けられ、
以下のドキュメントを参考にツールのインストールを行いました。
https://docs.bitnami.com/installer/how-to/understand-bncert/


cd ~
wget -O bncert-linux-x64.run https://downloads.bitnami.com/files/bncert/latest/bncert-linux-x64.run
sudo mkdir installdir
sudo mkdir installdir/bncert
sudo mv bncert-linux-x64.run installdir/bncert/
sudo chmod +x installdir/bncert/bncert-linux-x64.run

最後に、ツールを実行します。


sudo ./installdir/bncert/bncert-linux-x64.run

1. ドメイン名を聞かれます。入力してEnterを押してください
2. サーバーに設定を加える旨、同意を求められるので特に何もなければ[Y]を入力後、Enterを押してください。www->non wwwへのリダイレクトが不要など、除きたい設定があれば[No]を入力し、必要な設定を取捨選択してください。
3. ご自身のメールアドレスを入力してください
4. Let's Encryptを使う上での同意書のURLと、それに同意するか質問されます。pdfを読んだ後[Y]を入力し、Enterを押してください。
5. しばらくすると設定が完了した旨メッセージが表示されます。Enterを押してください。

最後に

以上で設定が完了します。
お使いのドメインにhttpsでアクセスし、証明書が有効になっていることを確認してください。
また、crontabにコマンドが挿入され、期限が切れる前に自動的に証明書をアップデートする仕組みとなっているようです。
自身の手順の備忘録となってしまいますが
もしも同じ問題でハマっている方のヒントになれば幸いです。