2 C
Senior Writer and partner

How to install Wagtail on Ubuntu 18.04?

As today almost everything has to do with the Internet and blogs, there are many CMS available. In this post, I will show you how to install Wagtail on Ubuntu 18.04. Of course, I will also tell you about this great CMS new and very well designed.

Wagtail is built with Python

We have talked about many CMS on this website. Some with very new features and others simpler and focused on a very specific audience. But Wagtail is something different.

Wagtail is an open source CMS that is built with Django and therefore in Python. This has many advantages in the execution of the application. Above all in issues of performance and clarity of code.

On the other hand, many well-known companies use Wagtail to build some websites, like Mozilla or BMW. So, we are in the presence of a quite powerful CMS.

- Advertisement -

Some of its main features focus on fast content editing using blocks; likewise, Wagtail has a form builder and integrates elasticsearch to do intelligent searches.

Finally, Wagtail wants the user not to waste too much time on configurations. He only spends time perfecting the website. That is to say, it is a CMS out the box. Everything is working for the first time.

So, let us install Wagtail.

First steps to install Wagtail

First, we need to update the system so that all the security patches are properly installed.

Open a terminal or connect to your SSH server and run the following:

:~$ sudo apt update
:~$ sudo apt upgrade

Then you need to install Python, Python PIP and the tool to create virtual environments with Python. So you have to run this command to do it.

:~$ sudo apt install python3 python3-pip python3-venv

Create a virtual environment for Wagtail

The next step is to create a virtual Python environment for Wagtail. This way we will be able to isolate the installation and create more security. Besides that, it will facilitate the installation together with PIP. First, install it.

:~$ sudo pip3 install virtualenv

1.- install Python env
1.- install Python env

Then, create a new user. And add it to the sudoers file.

:~$ sudo useradd -m -s /bin/bash wag
:~$ sudo passwd wag
passwd: password updated successfully
:~$ sudo nano /etc/sudoers

Next, create a virtual environment.

:~$ su - wag
:~$ virtualenv wagtail

2.- Create the python environment
2.- Create a python environment

You can replace “wagtail” for any name what you want.

Install Wagtail

Now that we have the virtual environment created, we will be able to install Wagtail. However, first, we must activate it.

:~$ source ~/wagtail/bin/activate

Now, you can install Wagtail.

:~$ pip install wagtail

3.- Install Wagtail on Ubuntu 18.04
3.- Install Wagtail on Ubuntu 18.04

In this case, the command is PIP and not PIP3. This is because, in Python virtual environments, the PIP command does not distinguish from the version used. Therefore, it will always be PIP regardless of the version we have.

Now,  we can create a new project.

:~$ cd ~
:~$ wagtail start [project_name]

4.- Create a new wagtail project
4.- Create a new wagtail project

Then, after the project directory is created. You need to follow these commands to start the new project.

:~$ cd [project_name]
:~$ python manage.py migrate
:~$ python manage.py createsuperuser
:~$ python manage.py runserver

Now, open your web browser and go to http://server-ip:8000. Remember to open the port on the firewall.

5.- Wagtail running
5.- Wagtail running

And you can go to the admin page on http://server-ip:8000/admin. You can log in with the super user previously created.

6.- Wagtail admin
6.- Wagtail admin

Install Gunicorn

Wagtail is an application built in Django. In that aspect, to deploy it is convenient to use a request manager that runs in Python. But ironically, Python is not the best for processing all requests. In this sense, I will use Gunicorn and link it to the project. Then, I’ll install Nginx.

:~$ pip install gunicorn
:~$ cd ~/wagproject
:~$ python manage.py collectstatic
:~$ deactivate
:~$ exit

7.- Getting gunicorn to install Wagtail correctly
7.- Getting gunicorn to install Wagtail correctly

Now, create a new systemd file to manage gunicorn like a service.

:~$ sudo nano /etc/systemd/system/gunicorn.service

And add the following:

Description=Gunicorn Daemon file

ExecStart=/home/wag/wagtail/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/wag/wagproject.sock wagproject.wsgi:application


8.- Creating a systemctl service for gunicorn
8.- Creating a systemctl service for gunicorn

Remember, change the user name and the project name so that everything works well.

Press CTRL + O to save the changes and CTRL + X to close the file.

Next, reload all systemd daemon to apply the changes.

:~$ sudo systemctl daemon-reload

Then, start gunicorn.

:~$ sudo systemctl start gunicorn

Install Nginx

As I mentioned earlier, Python is not the best at processing requests. Then, with Nginx, we will be able to improve all that request flow. So let’s install it

:~$ sudo apt install nginx

Now let’s create a new Nginx server block file.

:~$ nano /etc/nginx/sites-enabled/your-domain.conf

Add the following:

server {
    listen 80;
    server_name your-domain.com;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/wag/wagproject;

    location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://unix:/home/wag/wagproject.sock;

Save the changes and close the file.

Then, assign permissions on the project folder and add the new user to the www-data group.

:~$ sudo usermod -aG www-data wag
:~$ sudo chmod -R 710 /home/wag

Finally, start and enable Nginx.

:~$ sudo systemctl enable nginx
:~$ sudo systemctl start nginx

Now, you can access to Wagtail using your web browser to your domain.

And that is it.


Please enter your comment!
Please enter your name here

Latest article