How To Install Wagtail on CentOS 7

Wagtail on CentOS 7

Wagtail is a free and open source Content Management System written in Python and constructed on Django. It is easy, fast, beautiful and provides a fast, appealing interface for both editors. Wagtail is a flexible Django content management program focused on flexibility and consumer expertise.

Table of Contents

Step 1. First let’s start by ensuring your system is up-to-date.

Step 2. Installing Required Packages.

Step 3. Create a new system user.

Step 4. Installing Wagtail.

Step 5. Create a python virtual environment and your Wagtail project.

Step 6. Installing and configure Nginx and uWSGI.

Step 6. Wagtail CMS.

 

Prerequisites

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root accge of Linount, if not you may need to add ‘sudo’ to the commands to get root privileges. I will show you through the step by step installation Wagtail CMS on a CentOS 7 server.
Install Wagtail on CentOS 7

Step 1. First let’s start by ensuring your system is up-to-date.

yum clean all
yum -y install epel-release
yum -y update

Step 2. Installing Required Packages.

Install necessary packages:

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

Step 3. Create a new system user.

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

adduser --comment 'Wagtail User' --home-dir /home/wagtail wagtail
chmod 755 /home/wagtail

Step 4. Installing Wagtail.

Next, install Wagtail with the pip command as below:

pip install wagtail

Step 5. Create a python virtual environment and your Wagtail project.

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

su - wagtail

Create a new Wagtail project:

wagtail start mysite

Create a new virtualenv using the following command:

virtualenv wagtail-env

Switch to the new virtualenv:

source ~/wagtail-env/bin/activate

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

cd mysite
pip install -r requirements.txt

Next, create a new SQLite database:

python manage.py migrate
python manage.py createsuperuser

Step 6. Installing and configure Nginx and uWSGI.

Add the official Nging repository first:

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:

yum install nginx -y

Next, create a new Nginx vhost:

nano /etc/nginx/conf.d/YOUR_WAGTAIL_DOMAIN.conf

Add the following lines:

server {
 server_name your-domain;
 
 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/mywagtailsite_error.log;
 access_log /var/log/nginx/mywagtailsite_access.log;

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

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

pip install --upgrade uwsgi

Create uwsgi configuration file for Wagtail:

mkdir /etc/uwsgi.d/
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/mysite/
wsgi-file = mysite/wsgi.py
socket = /home/wagtail/mysite/mysite/%n.socket
stats = /home/wagtail/mysite/mysite/%n.stats.socket
logto = /home/wagtail/mysite/mysite/%n.log
workers = 4
uid = wagtail
gid = wagtail
limit-as = 512

Next, create a new service file for Wagtail:

nano /etc/systemd/system/uwsgi.service

Add the following code 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

Start uWSGI service and enable it to start on boot with the following command:

systemctl enable uwsgi
systemctl start uwsgi

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

systemctl enable nginx
systemctl start nginx

Step 6. Wagtail CMS.

Wagtail CMS will be available on HTTP port 80 by default. Open your favorite browser and navigate to http://yourdomain.com/ or http://server-ip and complete the required the steps to finish the installation.

Congratulation’s! You have successfully installed Wagtail. Thanks for using this tutorial for installing Wagtail CMS on CentOS 7 systems. For additional help or useful information, we recommend you to check the official Wagtail CMS web site.