Learn how to build a Strapi application using the Cloud Databases PostgreSQL® service.
NOTE: OVHcloud provides services for which you are responsible for their configuration and management. You are therefore responsible for their proper functioning.
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 existing nodejs installation matches "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:
NOTE: nodejs version >= 18 is required for this setup. This tutorial uses v20.11.0. No specific version of yarn is specified; this tutorial was made with the v1.22.21.
Declare the NodeJS version
Use this command to list the versions of NodeJS:
Install the latest version of NodeJS:
Check the version:
Set up 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. Then, select JavaScript and press Enter.
NOTE: If you choose the Quickstart option, 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. Database parameters can be found in the OVHcloud Control Panel.
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.
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:
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.
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 from the Configuration tab:
Go further
For more information and tutorials, please see our other Managed Databases & Analytics or Platform as a Service guides. You can also explore the guides for other OVHcloud products and services.
OVHcloud Managed Databases and Analytics:
- Grafana® is a registered trademark of Grafana Labs and is used with the permission of Grafana Labs. OVH SAS and its subsidiaries are not affiliated with or endorsed by Grafana Labs.
- Kafka® is a registered trademark of The Apache Software Foundation and has been licensed for use by OVHcloud, who has no affiliation with and is not endorsed by The Apache Software Foundation.
- MongoDB® is a registered trademark of MongoDB, Inc.
- MySQL® is a registered trademark of Oracle and/or its affiliates.
- PostgreSQL® is a registered trademark of the PostgreSQL Community Association of Canada.