Learn how to install Wagtail and how to connect it to the OVHcloud Managed Databases (also called Cloud Databases) PostgreSQL database service.
Wagtail is a free and open-source content management system (CMS) written in Python. It is popular amongst websites using the Django framework.
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. OVHcloud can't provide you with technical support in this regard.
Requirements
- access to the OVHcloud Control Panel
- a Public Cloud project in your OVHcloud account
- an up-and-running Cloud Database for PostgreSQL
- a Python environment with a stable version and public network connectivity (Internet)
Configure your PostgreSQL instance to accept incoming connections
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 under Databases & Analytics and select your PostgreSQL instance.
Step 1: Verify your user roles and password
Select the Users
tab. Verify that you have a user 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.
Step 2: Authorize incoming connections from the PostgreSQL client
In this step, select the Authorized IPs
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 authorize a new IP, and enter the previously found IP of your Python environment. In our case, we will enter 109.190.200.59.
To install the libjpeg and zlib libraries use the following command pairs:
-
sudo apt update
andsudo apt install libjpeg-dev
-
sudo apt update
andsudo apt install zlib1g-dev
Instructions
Create and activate a virtual environment
Create an isolated virtual environment for your Python projects that can have unique dependencies, regardless of any other project's dependencies:
$ python3 -m venv mysite/env
Set up your shell to execute Python packages by default:
$ source mysite/env/bin/activate
Install Wagtail
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
Generate your site
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:
This command will start the mysite folder created in the first step of this guide and the second "mysite" in the command specifies that a new directory should be created in your current home directory and that wagtail should start there.
$ wagtail start mysite mysite
Install project dependencies
$ pip install -r requirements.txt
Create the database
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:
Information | Location |
---|---|
db Host | General information tab, in the Login information box. |
db Port | General information tab, in the Login information box. |
db Name | Databases tab, usually "defaultdb" |
db User | Users tab, usually "avnadmin" |
db Password | Displayed in Users tab after resetting. |
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:
$ python3 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 to update the database.
Create an admin user
When logged into the admin site, a superuser has full permissions and can view/create/manage the database.
$ python manage.py createsuperuser
Start the server
Run the following command, specifying the IP address of the virtual machine running wagtail.:
python3 manage.py runserver <virtual machine running python ip>:8000
If the previous steps were successful, http://<your VM's IP>:8000
will show you a welcome page:
You can now access the administrative area at http://<your VM's IP>/admin
:
Cleaning up
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/mysite/
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.