• Get In Touch
June 6, 2017

How to Install Wagtail CMS on CentOS 7

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Wagtail is a free and open source Content Management System written in Python and built on Django.

It is simple, fast, beautiful and provides a fast attractive interface for editors. Wagtail is a flexible Django content management system focused on flexibility and user experience.

It comes with lots of features, some of them are listed below:

  1. Support for multiple language and sites.
  2. Provides an attractive interface for authors and editors.
  3. Comes with integrated search.
  4. Supports embedded content.
  5. Easily build and manage custom forms.

In this guide, we will go through how to install Wagtail on CentOS 7 with Nginx.

Requirements

  • A fresh server running CentOS 7.
  • A non root user with sudo privileges setup on your server.

Install Required Packages

Before starting, let’s start to install the EPEL repository on your CentOS 7 server.

sudo yum install epel-release -y

After installing the EPEL repository, update your system’s package repository with the latest version with the following command:

sudo yum update -y

Once your system is up to date, install required packages by running the following command:

sudo yum install python-pip python-virtualenv pcre-devel python-imaging python-devel libjpeg-turbo-devel make gcc -y

Once all the packages are installed, you can proceed to install Wagtail.

Install Wagtail

Before installing Wagtail, you will need to create a new system user for Wagtail.

To do so, run the following command:

sudo adduser --home-dir /home/wagtail wagtail

Next, give proper permissions to the Wagtail home directory with the following command:

sudo chmod 755 /home/wagtail

Next, install Wagtail with the pip command as below:

sudo pip install wagtail

Once Wagtail is installed, you will need to create a python virtual environment and your Wagtail project.

First, switch to wagtail user with the following command:

su - wagtail

Next, create a new Wagtail project with the following command:

wagtail start newsite

Next, create a new virtualenv using the following command:

virtualenv wagtail-env

Next, activate the new virtual environment witht the following command:

source ~/wagtail-env/bin/activate

Next, install all the required dependencies by running the pip command:

(wagtail-env)[wagtail]$ cd newsite
(wagtail-env)[wagtail]$ pip install -r requirements.txt

Next, you will need to create a new SQLite database and an admin user. You can do this by running the following command:

(wagtail-env)[wagtail]$ python manage.py migrate
(wagtail-env)[wagtail]$ python manage.py createsuperuser

Once you are done, you can proceed to install Nginx.

Install and Configure Nginx

By default Nginx is not available in the CentOS 7 repository, so you will need to add the official Nging repository first.

To add the Nginx repository, run the following command:

sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

Once Nginx repository is installed, install Nginx with the following command:

sudo yum install nginx -y

Next, create a new Nginx virtual host file with the following command:

sudo nano /etc/nginx/conf.d/Wagtail.conf

Add the following contents:

server {
    server_name yourdomain.com;

    client_body_in_file_only clean;
    client_body_buffer_size 64K;
    client_max_body_size 40M;
    sendfile on;
    send_timeout 300s;

    error_log /var/log/nginx/wagtail_error.log;
    access_log /var/log/nginx/wagtail_access.log;

    location / {
        uwsgi_pass      unix:/home/wagtail/newsite/newsite/wagtail.socket;
        include         /etc/nginx/uwsgi_params;
        uwsgi_param     UWSGI_SCHEME $scheme;
        uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;
    }
}

Save and close the file when you are finished.

Next, you will need to install uWSGI to your server.

You can install it by using the pip command as below:

sudo pip install --upgrade uwsgi

Next, create a uwsgi configuration file for Wagtail.

sudo mkdir /etc/uwsgi.d/

sudo nano /etc/uwsgi.d/wagtail.ini

Add the following lines:

[uwsgi]
chmod-socket = 666
virtualenv = /home/wagtail/wagtail-env
mount  = /=wsgi:application
chdir  = /home/wagtail/newsite/
wsgi-file = newsite/wsgi.py
socket = /home/wagtail/newsite/newsite/%n.socket
stats  = /home/wagtail/newsite/newsite/%n.stats.socket
logto  = /home/wagtail/newsite/newsite/%n.log
workers = 4
uid = wagtail
gid = wagtail
limit-as = 512

Save and close the file when you are finished.

Next, create a new service file for Wagtail.

sudo nano /etc/systemd/system/uwsgi.service

Add the following lines:

[Unit]
Description=uWSGI Emperor Service
After=syslog.target

[Service]
ExecStart=/usr/bin/uwsgi --master --die-on-term --emperor /etc/uwsgi.d
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=SIGINT
Restart=always
Type=notify
StandardError=syslog
NotifyAccess=all

[Install]
WantedBy=multi-user.target

Save the file, then start uWSGI service and enable it to start on boot with the following command:

sudo systemctl start uwsgi
sudo systemctl enable uwsgi

Finally, start Nginx service and enable it to start on boot time with the following command:

sudo systemctl start nginx
sudo systemctl enable nginx

Once you are done, you can proceed to access the Wagtail web interface.

Access Wagtail

Before accessing the Wagtail web interface, you will need allow port 80 through firewalld.

You can do this by running the following command:

sudo firewall-cmd --permanent --zone=public --add-port=80/tcp

Next, reload the firewalld with the following command:

sudo firewall-cmd --reload

Finally, open your web browser and type the URL http://yourdomain.com/, then complete the required steps to finish the installation.

Conclusion

I hope you now have enough knowledge to install and configure Wagtail on CentOS 7 server. You can now easily deploy it to your production environment.

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Share this Article!

Related Posts

Node.js Authentication – A Complete Guide with Passport and JWT

Node.js Authentication – A Complete Guide with Passport and JWT

Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will be avoided or at least […]

Node.js and MongoDB: How to Connect MongoDB With Node

Node.js and MongoDB: How to Connect MongoDB With Node

MongoDB is a document-oriented NoSQL database, which was born in 2007 in California as a service to be used within a larger project, but which soon became an independent and open-source product. It stores documents in JSON, a format based on JavaScript and simpler than XML, but still with good expressiveness. It is the dominant […]

Using MySQL with Node.js: A Complete Tutorial

Using MySQL with Node.js: A Complete Tutorial

Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you need to scale an application, […]

Node.Js Vs Django: Which Is the Best for Your Project

Node.Js Vs Django: Which Is the Best for Your Project

Django and NodeJs are two powerful technologies for web development, both have great functionality, versatile applications, and a great user interface. Both are open source and can be used for free. But which one fits your project best? NodeJs is based on JavaScript, while Django is written in Python. These are two equally popular technologies […]

Nodejs Vs PHP:  Which Works Best?

Nodejs Vs PHP: Which Works Best?

Before getting into the “battle” between Node.js and PHP we need to understand why the issue is still ongoing. It all started with the increased demand for smartphone applications, their success forcing developers to adapt to new back-end technologies that could handle a multitude of simultaneous requests. JavaScript has always been identified as a client-side […]