---
title: "PostgreSQL® - Tutorial - Install Wagtail and connect it to your service"
description: "Learn how to install Wagtail and how to connect it to the OVHcloud Cloud Databases PostgreSQL® database service."
url: https://docs.us.ovhcloud.com/en/public-cloud/databases/postgresql-tutorial-install-wagtail-connect-service
lang: en
---
> For AI agents: the complete documentation index is available at https://docs.us.ovhcloud.com/en/llms.txt, the full documentation bundle is available at https://docs.us.ovhcloud.com/en/llms-full.txt.

# PostgreSQL® - Tutorial - Install Wagtail and connect it to your service

**Learn how to install [Wagtail](https://wagtail.org/) and how to connect it to the OVHcloud Cloud Databases [PostgreSQL®](https://www.postgresql.org/) [database service](https://us.ovhcloud.com/public-cloud/postgresql/).**

[Wagtail](https://wagtail.org/) is a free and open-source content management system (CMS) written in Python. It is popular amongst websites using the [Django framework](https://www.djangoproject.com/).

**Warning:**

**NOTE:** 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. OVHcloud can't provide you with technical support in this regard.

 

## Requirements

- Access to the [OVHcloud Control Panel](https://manager.us.ovhcloud.com/)
- A [Public Cloud project](https://us.ovhcloud.com/public-cloud/) in your OVHcloud account
- An up-and-running Cloud Database for PostgreSQL®
- A Python environment with a stable version and public network connectivity (Internet)

**Note:**

This tutorial was made using Python 3.10.12. Wagtail supports Python 3.7, 3.8, 3.9, and 3.10.

 

## Configure your PostgreSQL[®](#go-further) 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](https://manager.us.ovhcloud.com/) and open your database via the `Public Cloud` and `Databases` menus.

 

### 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](https://www.postgresql.org/docs/current/database-roles.html) 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 "READY" in the Control Panel.

 

### Step 2: Authorize incoming connections from the PostgreSQL® client

In this step, select the `Configuration` 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.

In the **IPs** panel, enter the previously found IP of your Python environment and click the add `+` button.

Click `Save changes` when you are finished.

**Note:**

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 authorized.

**Warning:**

**NOTE:** 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).

To install the libjpeg and zlib libraries, use the following command pairs:

- `sudo apt update` and `sudo apt install libjpeg-dev`
- `sudo apt update` and `sudo 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:

Depending on your version, you might need to use "python" rather than "python3" in the command below.

```bash
$ python3 -m venv mysite/env
```

Set up your shell to execute Python packages by default:

```bash
$ source mysite/env/bin/activate
```

**Note:**

If you’re using version control (e.g., git), mysite will be the directory for your project. The env directory inside it should be excluded from any version control.

 

### Install Wagtail

Please follow the [official documentation](https://docs.wagtail.org/en/stable/getting_started/tutorial.html) to install Wagtail.

Below, you will find a resume of the installation process

Use pip, which is packaged with Python, to install Wagtail and its dependencies:

```bash
$ 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

```bash
$ pip install -r requirements.txt
```

 

### Create the database

If you keep Wagtail on default settings, a local SQLite 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, etc.). 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](https://manager.us.ovhcloud.com/) are:

| Information | Location                                                  |
| ----------- | --------------------------------------------------------- |
| db Host     | **Dashboard** tab, in the **Connection information** box. |
| db Port     | **Dashboard**, in the **Connection information** box.     |
| db Name     | **Databases** tab, usually "defaultdb"                    |
| db User     | **Users** tab, usually "avnadmin"                         |
| db Password | Displayed in **Users** tab after resetting.               |

```python
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.

```sh
rm -rf /home/my/app/path/mysite/
```

To clean your PostgreSQL®, use the OVHcloud Control Panel to delete your managed PostgreSQL® service from the `Configuration` tab:

 

## Go further

Browse all the [Databases guides](https://docs.us.ovhcloud.com/en/public-cloud/databases/landing-page-databases.md).

Browse the rest of the [OVHcloud US documentation](https://docs.us.ovhcloud.com/en/index.md) for guides on our other products and services.

Learn more about [Managed Databases](https://us.ovhcloud.com/public-cloud/databases/) on the OVHcloud US website.

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.
