Set up a Wagtail Website on Alibaba Cloud (Part 1)

Erick Otenyo
3 min readJun 11, 2020

--

In this tutorial we are going to set up a wagtail website on an Alibaba Cloud Ubuntu 16.04 ECS instance.
The first part of this tutorial will involve setting up Python,Django, Postgres, Nginx, and Gunicorn and a virtual environment.
Part 2 will involve setting up a simplistic wagtail website

Prerequisites

Inorder to follow through this tutorial smoothly and successfully, you will need the following:

  1. A valid Alibaba Cloud account. If you don’t have one already, sign up to the Free Trial to enjoy up to 40 Products for Free Worth $450-$1300 USD. Now up to 12 Months Usage for Elastic Compute Service
  2. An ECS instance running Ubuntu 16.04. You can select your preferred region and configurations; this will not affect the outcome of the server setup.
  3. A root password for your server.

Step 1: Install Python package Manager

We will install pip which is python package manager that enables us to install additional compoments for our future wagtail website. Run the following commands:

sudo apt updatesudo apt install python3-pip python3-dev libpq-dev postgresql postgresql-contrib nginx curl

This will install pip, the Python development files needed to build Gunicorn later, the Postgresql database system and the libraries needed to interact with it, and the Nginx web server.

Step 2: Create a PostgreSQL Database User and Password

Creating a postgresql database and password for our wagtail website is super straight forward. First, log in to postgresql interactive interface by typing:

sudo -u postgres psql

Next create a database. Feel free to replace mywebsite with a prefered database name.

CREATE DATABASE mywebsite;

Create a database user for the website and ensure to provide a secure passowrd:

CREATE USER mywebsite WITH PASSWORD 'password';

Next we shall configure a few connection parameters. We are setting the default encoding to UTF-8, which Django expects. Also, set the default transaction isolation scheme to “read committed”, which blocks reads from uncommitted transactions. Finally, we are setting the timezone.

ALTER ROLE mywebsiteuser SET client_encoding TO 'utf8';
ALTER ROLE mywebsiteuser SET default_transaction_isolation TO 'read committed';
ALTER ROLE mywebsiteuser SET timezone TO 'UTC';

Let’s give our new user access to our newly created database mywebsite

GRANT ALL PRIVILEGES ON DATABASE mywebsite TO mywebsiteuser;

To exit postgres interface when done, type:

\q

Step 3: Create a Python Virtual Environment

A virtual environment is a Python environment such that the Python interpreter, libraries and scripts installed into it are isolated from those installed in other virtual environments. To create one we need to first upgrade pip then install virtualenv package:

sudo -H pip3 install --upgrade pip
sudo -H pip3 install virtualenv

With virtaulenv installed, let’s create a virtual environment:

virtualenv mywebsitetenv

Before we can start creating our wagtail website let’s first activate our virtual environment:

source myprojectenv/bin/activate

With our virtual environment activated, let’s create Django, Gunicorn,Wagtail and the psycopg2 PostgreSQL adaptor with the local instance of pip:

pip install django gunicorn psycopg2-binary wagtail

If you have come this far it means you have successfully setup a Python,Django, Postgres, Nginx, and Gunicorn and a virtual environment. You are now ready to create a wagtail website. Let’s go to part 2.

--

--

Erick Otenyo

Data, Code and Maps! Working on Climate Data for actionable insights.