Lab - Setting up Strapi
In searching for an open-source blogging site for self hosting, in addition to static site generators, I also tried Ghost, Strapi, Payload, among others. Strapi can be useful later when I want to define own data models that can be exposed as an API service for other use cases.
Preparation
- Prepare Node.js stack, nvm, npm, etc.
- Setup websites using Nginx Proxy Manager (a different NPM)
Installation
Visiting Quick Start Guide and looking around a bit for Docker installation, it is suggested to create a Strapi project, and see how to deploy using Docker, compared to looking for an official Docker image and start from there. This is what I'll do below, and later use NPM for proxying. Dockerization will be left later until needed.
So as usually create a project folder with name strapp
:
mkdir strapp
cd strapp
Inside with I create a Strapi project using yarn
:
$ yarn create strapi
...
? Please log in or sign up. Skip
? Do you want to use the default database (sqlite) ? Yes
? Start with an example structure & data ? Yes
? Start with Typescript? Yes
? Install dependencies with yarn? Yes
? Initialize a git repository? No
After installation completes, I got some info and a list helpful commands:
info: The Users & Permissions plugin automatically generated a jwt secret and stored it in .env under the name JWT_SECRET.
...
✓ Sample data added to your database
Strapi Your application was created!
Available commands in your project:
Start Strapi in watch mode. (Changes in Strapi project files will trigger a server restart)
yarn run develop
Start Strapi without watch mode.
yarn run start
Build Strapi admin panel.
yarn run build
Deploy Strapi project.
yarn run deploy
Seed your database with sample data.
yarn run seed:example
Display all available commands.
yarn run strapi
To get started run
cd /home/uvw/uvw/uvw-strapi/uvw-docs
yarn run develop
Assuming I gave the name strapi
as the project name, looking at strapi/.env
we can see some environment variables that might be needed later.
I can launch the instance now:
$ cd strapi
$ yarn develop
We see the output:
yarn run v1.22.22
$ strapi develop
✔ Cleaning dist dir (9ms)
⠋ Loading Strapi⠋ Building build context
[INFO] Including the following ENV variables as part of the JS bundle:
- ADMIN_PATH
- STRAPI_ADMIN_BACKEND_URL
- STRAPI_TELEMETRY_DISABLED
✔ Building build context (63ms)
✔ Creating admin (299ms)
✔ Loading Strapi (1186ms)
✔ Generating types (332ms)
✔ Cleaning dist dir (26ms)
✔ Compiling TS (1842ms)
Project information
┌────────────────────┬──────────────────────────────────────────────────┐
│ Time │ ... │
│ Launched in │ 3385 ms │
│ Environment │ development │
│ Process PID │ 473825 │
│ Version │ 5.0.3 (node v20.17.0) │
│ Edition │ Community │
│ Database │ sqlite │
└────────────────────┴──────────────────────────────────────────────────┘
Actions available
One more thing...
Create your first administrator 💻 by going to the administration panel at:
┌─────────────────────────────┐
│ http://localhost:1337/admin │
└─────────────────────────────┘
[...] info: Strapi started successfully
I probably can visit the site if it were launched locally. Right now it is installed on a VPS in the cloud. I want to access it via HTTPS at some domain name, so I started to deploy it immediately using NPM.
Serving Strapi via NPM
On the VPS, let's say I have obtained the domain name mystrapi.mydomain
. Since the Strapi instance is not running as a container in the same network as the NPM is, NPM needs to access it from within the Docker network.
Assuming we use "normal" Docker setup and concern ourselves with default bridge network only. To check the IP address of the gateway between the Docker host and the bridge network (usually 172.17. 0.1
), we can run
$ docker network inspect bridge
...
"IPAM": {
...
"Config": [
{
"Subnet": "172.17.0.0/16",
"Gateway": "172.17.0.1"
}
]
},
You can also check the network interface for docker0
(ifconfig
or ip address show dev docker0
).
Then we can setup NPM by creating an entry for the Strapi instance with an SSL certificate, and forwarding it to http://172.17.0.1:1337
.