PostgreSQL - Tutorial - Install Wagtail and connect it to OVHcloud Managed PostgreSQL service
Find out how to install Wagtail and connect it to an OVHcloud Managed PostgreSQL service
Find out how to install Wagtail and connect it to an OVHcloud Managed PostgreSQL service
Last updated 11th February 2022
Wagtail is a free and open source content management system (CMS) written in Python. It is popular amongst websites using the Django framework.
In this tutorial, we are going to show you how to install Wagtail and how to connect it to 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 on https://community.ovh.com/en/. OVHcloud can't provide you with technical support in this regard.
Wagtail supports Python 3.7, 3.8, 3.9 and 3.10.
Before making a connection, we need to verify that our PostgreSQL instance is correctly configured.
Log in to your OVHcloud Control Panel and open your Public Cloud
project. Click on Databases
in the left-hand navigation bar and select your PostgreSQL instance.
Select the Users
tab. Verify that you have a user with sufficient rights and a configured password. If you don't remember the user's password, you can either create a new user or regenerate the password of an existing user. Be careful! By doing so you will need to update all the places where you already use this user/password pair.
This first user avnadmin comes with the following privileges:
LOGIN
NOSUPERUSER
INHERIT
CREATEDB
CREATEROLE
REPLICATION
We rely on official PostgreSQL roles and privileges. You can manage them yourself via CLI or code. So far, user grants and privileges management are not supported via the OVHcloud Control Panel or the OVHcloud API.
Please read the official PostgreSQL documentation to select the right roles for your use case.
In our example, we will simply reset the avnadmin password.
Once created or updated, the user has to be ready and have the status "Enabled" in the Control Panel.
In this step, select the Authorised IP's
tab (Access Control List).
By default, a Public Cloud Database does not accept any form of connection from the outside world.
This way we can help prevent intrusive connection attempts.
Click to authorise a new IP, and enter the previously found IP of your Python environment. In our case we will enter 109.190.200.59.
If you want to allow any connections from the outside, you can enter the IP 0.0.0.0/0. Please use it carefully. Every IP will be authorised.
Before installing Wagtail, it is necessary to install the libjpeg and zlib libraries, which provide support for working with JPEG, PNG and GIF images (via the Python Pillow library).
$ python3 -m venv mysite/env
$ source mysite/env/bin/activate
If you’re using version control (e.g. git), mysite will be the directory for your project. The env directory inside of it should be excluded from any version control.
Please follow the official documentation to install Wagtail.
Below, you find a resume of the installation process
Use pip, which is packaged with Python, to install Wagtail and its dependencies:
$ pip install wagtail
Wagtail provides a start command similar to django-admin startproject. Running wagtail start mysite in your project will generate a new mysite folder with a few Wagtail-specific extras, including the required project settings, a “home” app with a blank HomePage model and basic templates, and a sample “search” app.
Because the folder mysite was already created by venv, run wagtail start with an additional argument to specify the destination directory:
$ wagtail start mysite mysite
$ cd mysite
$ pip install -r requirements.txt
If you keep wagtail on default settings, a local SQLlite database will be used inside the project directory. It’s fine for a PoC but not recommended for production, for multiple reasons (performance, security, resiliency, ...). Here we will configure Wagtail to use a Public Cloud Database for PostgreSQL as a backend.
Before creating the database, let's edit the mysite/mysite/settings/base.py
file and adapt the connection parameters to the database.
The useful parameters, available in the OVHcloud Control Panel are:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': <db_name>,
'USER': <username>,
'PASSWORD': <password>,
'HOST': <host>,
'PORT': <port>,
'OPTIONS': {
'sslmode': 'require'
}
}
}
Then create the database:
$ python manage.py migrate
This command ensures that the tables in your database are matched to the models in your project. Every time you alter your model (e.g. you may add a field to a model) you will need to run this command in order to update the database.
When logged into the admin site, a superuser has full permissions and is able to view/create/manage the database.
$ python manage.py createsuperuser
$ python manage.py runserver
If everything worked, http://127.0.0.1:8000
will show you a welcome page:
You can now access the administrative area at http://127.0.0.1:8000/admin
:
To clean your Wagtail, 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-wagtail/
To clean your PostgreSQL, use the OVHcloud Control Panel to delete your managed PostgreSQL service:
We would love to help answer questions and appreciate any feedback you may have.
Are you on Discord? Connect to our channel at https://discord.gg/ovhcloud and interact directly with the team that builds our databases service!
Please feel free to give any suggestions in order to improve this documentation.
Whether your feedback is about images, content, or structure, please share it, so that we can improve it together.
Your support requests will not be processed via this form. To do this, please use the "Create a ticket" form.
Thank you. Your feedback has been received.
Access your community space. Ask questions, search for information, post content, and interact with other OVHcloud Community members.
Discuss with the OVHcloud community