Construire une application Strapi connectée a Public Cloud Databases pour PostgreSQL (EN)
Objective
In this tutorial, we are going to show you how to build a Strapi application using the OVHcloud managed PostgreSQL database service.
OVHcloud provides services for which you are responsible for their configuration and management. You are therefore responsible for their proper functioning.
This tutorial is designed to help you as much as possible with common tasks. If you are having difficulty performing these actions, please contact a specialized service provider and/or discuss it with our community of users. OVHcloud can't provide you with technical support in this regard.
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 Public 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
Subscribing to the service
Log in to your OVHcloud Control Panel and switch to Public Cloud in the top navigation bar. After selecting your Public Cloud project, click on Databases in the left-hand navigation bar under Storage.
Click on the Create a database instance button. (Create a service if your project already contains databases.)
Step 1: Select PostgreSQL database
Click on the PostgreSQL database and then select the version to install from the drop-down menu.

Click Next to continue.
Step 2: Select a solution
In this step, choose an appropriate service plan. You will be able to upgrade the plan after creation.

Please visit the capabilities page for detailed information on each plan's properties.
Click Next to continue.
Step 3: Select a location
Choose the geographical region of the data center in which your database will be hosted.

Click Next to continue.
Step 4: Configure database nodes
You can choose the node model in this step. The initial and maximum numbers of nodes depend on the chosen solution in step 2.

Please visit the capabilities page for detailed information on the hardware resources and other properties of the MySQL database installation.
Take note of the pricing information and click Next to continue.
Step 5: Configure your options
You can name your database in this step.

Click Next to continue.
Step 6: Summary and confirmation
The last section will show a summary of your order as well as the API equivalent of creating this database instance with the OVHcloud API.

Click Create a database service to continue.
Within a few minutes your new database service will be deployed. Messages in the OVHcloud Control Panel will inform you when the database is ready to use.
Your database is ready when cluster status is "Ready", node status is green, and number of users is set to "1 user".

Authorize your IP address
For security reasons the default network configuration doesn't allow any incoming connections. To allow access from your application or development environment to your PostgreSQL database service, you must add your IP addresses to the service authorized list.
Add your IPs to the DB authorized list
Following the related documentation on how to authorize the suitable IP addresses, add your IPs to the authorized list.

Test connection to the PostgreSQL DataBase
A quick and easy way to test the connection is to use the Postgre Command Line Interface (CLI) psql.
💡 Tip : If you are familiar with Docker or Kubernetes, you can use the psql tool inside a postgres Docker image instead of installing the tool locally.
Examples :
kubectl run postgres-client --image=postgres:latest -it --rm --restart=Never -- /bin/bashor
docker run -it --rm postgres /bin/bash
Connect to the database
The useful parameters are:
- The db Host, the db Port
- Get them from the "General Information tab"
- The db Name
- Get it from the "Databases" tab, usually "defaultdb"
- The db User
- Get it from the "Users" tab, usually "avnadmin"
- The db Password
- Get it after you reset it.

Now connect to the database with the following command
Enter the password and press Enter.
Setup is done, your Managed PostgreSQL database is fully operational, let's go further and use it with Strapi.
Before you begin, prepare your environment
What you need here is to check your nodejs and yarn versions.
According to the official documention on GitHub, check that your existent nodejs installation matches with "NodeJS >= 12 <= 16".
No specific version of yarn is specified, this tutorial was made with the 1.22.17 one.
You can follow these different tutorials if you need to install some of the tools:
Declare the nodejs version
We want to use the latest LTS version of nodejs, so inside your development environment, use this command:
Setup a new instance of Strapi
Strapi offers a simple way to install its product, with yarn. Run the following command in a terminal:
You will be prompted to choose between the Quickstart or Custom method, select Custom and press Enter.
If you choose the Quickstart one, default parameters will be applied and a server will automatically start.
On the next step, select postgres and press Enter.
Then, enter your PostgreSQL database parameters, and select Yes when prompted for enabling SSL connection.
If you prefer to choose No when prompted to enable SSL connection, this is what happens:
This is a known bug, you can follow the issue here: https://github.com/strapi/strapi/issues/12058.
We can fix it by manually modifying the database configuration file.
Open the config/database.js file.
It should be similar to that:
Replace the line:
with this line:
Save and exit the file.
Now, if you choose Yes when prompted to enable SSL connection, get the CA certificate from the OVHcloud Control Panel:

Save the generated file into the config folder, just beside the database.js file, and rename it as ca-certificate.crt
Now open the config/database.js file and modify the ssl block as follows:
where ${__dirname} is the config folder location.
Save and exit the file, the configuration is done!
Start Strapi
Launch the strapi application with the yarn command:
Congratulations! You have just finished the setup, the server starts end open your browser on the admin login creation page http://localhost:1337/admin/auth/register-admin.

Fill 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 PosgreSQL database with psql command line interface.
Then find, in the up_users table, our previously created entry. Here the user is named "demo":
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.
To clean your PostgreSQL, use the OVHcloud Control Panel to delete your managed PostgreSQL service:

We want your feedback!
We would love to help answer questions and appreciate any feedback you may have.
If you need training or technical assistance to implement our solutions, contact your sales representative or click on this link to get a quote and ask our Professional Services experts for a custom analysis of your project.
Are you on Discord? Connect to our channel at https://discord.gg/ovhcloud and interact directly with the team that builds our databases service!