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.
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
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 wag ALL=(ALL:ALL) ALL
Next, create a virtual environment.
:~$ su - wag :~$ virtualenv wagtail
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
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]
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 0.0.0.0:8000
Now, open your web browser and go to http://server-ip:8000. Remember to open the port on the firewall.
And you can go to the admin page on http://server-ip:8000/admin. You can log in with the super user previously created.
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
Now, create a new systemd file to manage gunicorn like a service.
:~$ sudo nano /etc/systemd/system/gunicorn.service
And add the following:
[Unit] Description=Gunicorn Daemon file After=network.target [Service] User=wag Group=www-data WorkingDirectory=/home/wag/wagproject ExecStart=/home/wag/wagtail/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/wag/wagproject.sock wagproject.wsgi:application [Install] WantedBy=multi-user.target
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.