Overview

I had the opportunity to run Strapi on Amazon Lightsail, so here are my notes. I referenced the following article:

https://zenn.dev/holykzm/articles/1e54cc25207657

Instance

Select Node.js.

Choose an instance with at least 1GB of memory. If you build on Lightsail, an out-of-memory error will occur with less.

SSL and Custom Domain

Please refer to the following:

https://zenn.dev/nakamura196/articles/5772d6c918508a#独自ドメインの付与

Assign a Static IP, configure a custom domain in Route 53, and run the following:

sudo /opt/bitnami/bncert-tool

ProxyPass Configuration

(There may be a more appropriate location, but) add the following to:

/opt/bitnami/apache2/conf/httpd.conf

# Add the following at the end
ProxyPass / http://localhost:1337/
ProxyPassReverse / http://localhost:1337/

Restart Apache:

sudo /opt/bitnami/ctlscript.sh restart apache

Installing Strapi

cd /opt/bitnami/apache2/htdocs/
npx create-strapi-app@latest backend --quickstart

The application will start, so stop it temporarily with Ctrl+C.

pm2

Installing pm2

sudo npm install pm2 -g

Creating server.js

cd /opt/bitnami/apache2/htdocs/backend
vi server.js

/opt/bitnami/apache2/htdocs/backend/server.js

const strapi = require('@strapi/strapi');
   strapi(/* {...} */).start();

Build

cd /opt/bitnami/apache2/htdocs/backend
NODE_ENV=production npm run build

Starting the Server

NODE_ENV=production pm2 start server.js --name strapi

With this, Strapi was successfully started as shown below.

Other Notes

  • Stopping the service
pm2 stop strapi
  • Editing content types

You need to start in development mode, so run the following:

npm run develop

After editing is complete, run the build and pm2 startup again.

cd /opt/bitnami/apache2/htdocs/backend
NODE_ENV=production npm run build
NODE_ENV=production pm2 start server.js --name strapi

Summary

In this case, I switched between development and production modes on Lightsail. However, as described in the following article, there are also methods using GitHub Actions, which I would like to try in the future.

https://datasciencedude.com/how-to-deploy-strapi-to-aws-lightsail-with-github-actions