Learn how to build a Strapi application using the Managed Databases (also called Cloud Databases) PostgreSQL service.
Before you begin
You need to be able to order a database solution in the OVHcloud Control Panel, as explained in our Getting Started with Cloud Databases guide.
As Strapi is written in Javascript, packages like nodejs, nvm, and yarn are necessary for this tutorial.
Instructions
Create a PostgreSQL database
To set up a PostgreSQL, follow the instructions in our PostgreSQL - Configure an Instance to Accept Incoming Connections guide.
Before you begin, prepare your environment
What you need here is to check your nodejs
and yarn
versions. According to the official documentation on GitHub, check that your existent nodejs installation matches with "NodeJS >= 12 <= 16".
You will require nodejs and yarn tools to configure and run Strapi App. These tools are available for various Linux, Windows, and MacOS Operating Systems. The installation steps are not provided in this guide but can be found in the links below:
Declare the NodeJS version
Use this command to list the versions of NodeJS:
nvm ls
Install the latest version of NodeJS:
nvm install <latest version>
Check the version:
node --version
Setup a new instance of Strapi
Strapi offers a simple way to install its product, with yarn. Run the following command in a terminal:
yarn create strapi-app my-strapi
You will be prompted to choose between the Quickstart or Custom method. Select Custom
and press Enter
. Then, select JavaScript and press Enter
.
$ yarn create strapi-app my-strapi
yarn create v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "create-strapi-app@4.17.1" with binaries:
- create-strapi-app
? Choose your installation type
Quickstart (recommended)
❯ Custom (manual settings)
? Choose your preferred language
❯ JavaScript
TypeScript
On the next step, select postgres
and press Enter
.
? Choose your default database client sqlite ❯ postgres mysql
Then, enter your PostgreSQL database parameters, and select Yes
when prompted for enabling SSL connection. Database parameters can be found in the OVHcloud Control Panel.
? Choose your installation type Custom (manual settings)
? Choose your preferred language JavaScript ? Choose your default database client postgres ? Database name: <database name> ? Host: <host address> ? Port: <port number> ? Username: <user name> ? Password: <password> ? Enable SSL connection: Yes Creating a project with custom database options. Creating a new Strapi application at /home/my/app/path/my-strapi. Creating files. Dependencies installed successfully. Your application was created at /home/my/app/path/my-strapi. Available commands in your project: yarn develop Start Strapi in watch mode. (Changes in Strapi project files will trigger a server restart) yarn start Start Strapi without watch mode. yarn build Build Strapi admin panel. yarn strapi Display all available commands. You can start by doing: cd /home/my/app/path/my-strapi yarn develop Done in 662.54s.
Get the CA certificate from the OVHcloud Control Panel:
Save the generated file into the config
folder inside the my-strapi folder, just beside the database.js
file, and rename it as ca-certificate.crt
Now open the config/database.js
file, find the block with your database information, and modify the ssl
line as follows. Add the following block with your database information at the end of database.js
file if it doesn't exist.
Make sure to update your Database Host Name, Port, and Password.
const fs = require('fs'); module.exports = ({ env }) => ({ connection: { client: 'postgres', connection: { host: env('DATABASE_HOST', 'postgresql-ab1cd2ef-gh1ij2kl3.database.cloud.ovh.us'), port: env.int('DATABASE_PORT', 20184), database: env('DATABASE_NAME', 'defaultdb'), user: env('DATABASE_USERNAME', 'avnadmin'), password: env('DATABASE_PASSWORD', 'MyStrongPassword'), ssl: { ca: fs.readFileSync(`${__dirname}/ca-certificate.crt`).toString(), } }, }, });
Where ${__dirname}
is the full path of the config
folder. Save and exit the file, the configuration is done!
Start Strapi
Launch the Strapi application with the yarn command:
yarn develop
$ yarn develop yarn run v1.22.17 warning ../../../package.json: No license field $ strapi develop Building your admin UI with development configuration ... Admin UI built successfully Project information ┌────────────────────┬──────────────────────────────────────────────────┐ │ Time │ Fri Dec 31 2021 13:26:35 GMT+0100 (Central Euro… │ │ Launched in │ 13253 ms │ │ Environment │ development │ │ Process PID │ 1861833 │ │ Version │ 4.0.2 (node v16.13.1) │ │ Edition │ Community │ └────────────────────┴──────────────────────────────────────────────────┘ Actions available One more thing... Create your first administrator 💻 by going to the administration panel at: ┌─────────────────────────────┐ │ http://localhost:1337/admin │ └─────────────────────────────┘ [2021-12-31 13:26:35.437] http: GET /admin (24 ms) 200 [2021-12-31 13:26:35.497] http: GET /admin/runtime~main.2d8596f7.js (7 ms) 200 [2021-12-31 13:26:35.498] http: GET /admin/main.dfa22c7a.js (3 ms) 200 [2021-12-31 13:26:35.775] http: GET /admin/project-type (1 ms) 200 [2021-12-31 13:26:35.808] http: GET /admin/497.726adbfa.chunk.js (2 ms) 200 [2021-12-31 13:26:35.813] http: GET /admin/2664.f33f619d.chunk.js (1 ms) 200 [2021-12-31 13:26:35.822] http: GET /admin/4362.c65ab24b.chunk.js (1 ms) 200 [2021-12-31 13:26:35.855] http: GET /admin/fontawesome-css.32df0f91.chunk.js (1 ms) 200 [2021-12-31 13:26:35.860] http: GET /admin/en-json.4c3c1c95.chunk.js (4 ms) 200 [2021-12-31 13:26:35.861] http: GET /admin/fr-json.c75e1a2e.chunk.js (2 ms) 200 [2021-12-31 13:26:35.870] http: GET /admin/fontawesome-css-all.90be2358.chunk.js (1 ms) 200 [2021-12-31 13:26:35.878] http: GET /admin/content-type-builder-translation-en-json.81257d0d.chunk.js (2 ms) 200 [2021-12-31 13:26:35.881] http: GET /admin/content-type-builder-translation-fr-json.2156f48c.chunk.js (4 ms) 200 [2021-12-31 13:26:35.885] http: GET /admin/email-translation-en-json.ef8208e3.chunk.js (5 ms) 200 [2021-12-31 13:26:35.886] http: GET /admin/email-translation-fr-json.76afb1c3.chunk.js (3 ms) 200 [2021-12-31 13:26:35.893] http: GET /admin/i18n-translation-en-json.a90b9dc5.chunk.js (5 ms) 200 [2021-12-31 13:26:35.894] http: GET /admin/upload-translation-en-json.d205cecd.chunk.js (5 ms) 200 [2021-12-31 13:26:35.897] http: GET /admin/i18n-translation-fr-json.482f6933.chunk.js (6 ms) 200 [2021-12-31 13:26:35.898] http: GET /admin/upload-translation-fr-json.0f4b3839.chunk.js (6 ms) 200 [2021-12-31 13:26:35.902] http: GET /admin/users-permissions-translation-en-json.3e650c44.chunk.js (7 ms) 200 [2021-12-31 13:26:35.904] http: GET /admin/users-permissions-translation-fr-json.12f3c930.chunk.js (4 ms) 200 [2021-12-31 13:26:35.906] http: GET /admin/fontawesome-js.2639263c.chunk.js (1 ms) 200 [2021-12-31 13:26:35.989] http: GET /admin/cropper-css.b71d1229.chunk.js (3 ms) 200 [2021-12-31 13:26:36.006] http: GET /admin/init (40 ms) 200 [2021-12-31 13:26:36.173] http: GET /admin/fde9b1ad0670d29a2516.png (1 ms) 200
Congratulations! You have just finished the setup, the server starts, and open your browser on the admin login creation page http://localhost:1337/admin/auth/register-admin.
Fill in the form fields as requested, and press the Let's start
button.
You are now using a Strapi app connected to an OVHcloud-managed PostgreSQL database.
Controls
Add an entry to Strapi
Using the admin interface, click on the Content Manager
menu, and add a user, such as:
Then press the Save
button.
Check the database
As described above, connect to the PostgreSQL database with psql
command line interface.
$ psql --dbname=defaultdb --host=postgresql-ab1cd2ef-gh1ij2kl3.database.cloud.ovh.us --port=20184 --username=avnadmin --password
Then find, in the up_users
table, our previously created entry. Here the user is named "demo":
defaultdb=> SELECT id,username,email,created_at FROM public.up_users WHERE username='demo'; id | username | email | created_at ----+----------+-----------------+------------------------ 1 | demo | demo@mymail.com | 2021-12-31 13:46:08.04 (1 row)
Cleaning up
To clean your Strapi, make sure it is closed by pressing CTRL+C
in the terminal you used to launch it, then delete your installation folder.
rm -rf /home/my/app/path/my-strapi/
To clean your PostgreSQL, use the OVHcloud Control Panel to delete your managed PostgreSQL service:
Go further
For more information and tutorials, please see our other Cloud Databases support guides or explore the guides for other OVHcloud products and services.