Wagtail CMS and Python-Based Cloud Hosting with Jelastic PaaS

13

2686-1-wagtail-logoWagtail CMS (content management system) is a simple and agile Django-powered CMS, which offers a convenient and intuitive interface for editors to create and structure website content. Wagtail is published under the BSD license, which provides you as much freedom as possible. The exceptional performance and optimization of this CMS ensure lightning-fast page loading and searches. With the advantages of Wagtail CMS, you can spend less time on configuring your website and more on perfecting your project (using a vast number of tools in the administration panel for working with content).

This article describes how to deploy Wagtail CMS into your Jelastic PaaS Python environment.

Create Python Environment

To start with, you need to create an environment with the appropriate application server – the Apache web server with the Python engine.

1. To create New Environment, log into your Jelastic PaaS dashboard and click the same-named button at the top-left corner.

2686-1-create-new-python-environment

2. In the opened topology wizard, switch to the Python tab and choose the required Python version for the automatically selected Apache application server node.

2686-1-python-application-server

Note: The latest Wagtail CMS versions support Python 3.x only. On the Python 2.7 instances, run the 1.13 version of the application.

Configure all other settings to your needs (e.g., cloudlet limit, disk space, region, etc.), set the desired domain name and click the Create button.

3. Wait a minute for your environment to be created.

2686-1-open-wagtail-cms-in-browser

Now, you are ready to start the Wagtail CMS application deployment. Below, we’ll overview how to deploy it automatically using the pre-packaged archive and manually from scratch.

Wagtail CMS Automatic Deployment

A prepared a deployment archive is available with an already configured Wagtail CMS of the latest version available at the moment (i.e., 2.2) and SQLite database, which can be installed in a matter of minutes without any manual configurations required.

Note: If configuring your own deployment archive, please ensure your Wagtail CMS package contains the following files in it’s root:

  • requirements.txt – file with the names of all the Python modules your application requires, it will be read by the deployment script to install the listed modules via the pip manager automatically;
  • wsgi.py – file with the entry point script for running your application inside a virtual environment by means of the mod_wsgi for Apache.

1. Upload the package with your Wagtail CMS application into your deployment manager via the following link:

https://download.jelastic.com/public.php?service=files&t=b01aabf6a7fb615884c27eb4101e5150&download

2686-1-wagtail-cms-deployment-manager

2. Deploy this archive into your Python 3.x environment.

2686-1-deploy-archive-into-python-environment

3. After the operation is finished, select the Open in Browser button next to your environment.

2686-1-open-wagtail-cms-environment-in-browser

4. That’s all! Now you can enjoy working with your Wagtail CMS application (the default credentials for the admin panel are – admin / verysecurepasswordforadmin).

2686-1-welcome-to-wagtail-cms-website

Enjoy your Wagtail CMS hosted at Jelastic PaaS!

Wagtail CMS Manual Deployment

For the manual Wagtail CMS application deployment, the process can be divided into three major steps: application installation, database configuration and running Wagtail CMS.

Install Wagtail CMS
1. Access your Apache application server via SSH. For example, we’ll utilize the inbuilt Web SSH tool.

2686-1-wagtail-cms-web-ssh-tool

2. It is a common practice to run Python web applications in isolated virtual environments, using the virtual environment tool. It allows keeping the dependencies required by different projects in separate places and manage them without the administrator privileges.

Execute the following commands to create and activate a new virtual environment:

virtualenv virtenv

source virtenv/bin/activate

2686-1-wagtail-cms-web-ssh-session

3. Now, download the Wagtail CMS installer using the pip package manager for Python:

pip install wagtail

2686-1-wagtail-cms-pip-package-manager-for-python

Note: If you are running the Python 2.7 instance, you need to specify the appropriate application version in your command explicitly, i.e., pip install wagtail==1.13.

4. Install the application to the ROOT context, so the existing folder (with the default application) should be removed beforehand:

rm -rf ROOT

wagtail start ROOT

2686-1-wagtail-cms-start-root

Next, you need to choose and configure a database.

Configure Database
As all the Django-based applications, Wagtail CMS supports different types of databases:

  • SQLite is a default solution, which is implemented by default and does not require any additional configurations (data will be stored locally in ~/ROOT/db.sqlite3) and it is suitable for development and test environments;
  • External SQL database (e.g., MySQL or PostgreSQL) is a much more secure option, which provides greater scalability and it is recommended for production environments.

Below, we’ll provide a step-by-step guide on connecting the external database to your Wagtail CMS application. Herewith, if the first option is sufficient for your purposes, skip this section and proceed to Run Wagtail CMS.

1. Create the desired database instance. For example, use the Change Environment Topology button to add the MariaDB database server to your environment with the Wagtail CMS installed.

2686-1-add-mariadb-environment

2. Open the database admin panel and log in with credentials from the appropriate email (automatically sent after the database node creation).

2686-1-mariadb-admin-panel

3. Navigate to the User accounts tab to create a user for accessing the Wagtail CMS database by clicking the Add user account link.

2686-1-mariadb-user-accounts-overview

4. Within the opened frame, specify the User name / Password and tick the Create database with same name and grant all privileges checkbox.

2686-1-create-new-mariadb-database

Click Go at the bottom of the page.

5. Return to the dashboard and open the /var/www/webroot/ROOT/ROOT/settings/base.py file. Locate the DATABASES section and add your database access credentials within the same section (as shown below):

DATABASES = {
   'default': {
       'ENGINE': 'django.db.backends.mysql',
       'NAME': 'wagtail',
       'USER': 'wagtail',
       'PASSWORD': 'passw0rd',
       'HOST': 'node22551-wagtail.jelastic.com',
       'PORT': '3306',
   }
}

2686-1-wagtail-local-database-settings

Here:

  • ENGINE – set database type to django.db.backends.mysql (or django.db.backends.postgresql_psycopg2 for PostgreSQL database);
  • NAME, USER, PASSWORD – provide your database access credentials;
  • HOST – set the database hostname;
  • PORT – set the default port to 3306 (or 5432 for PostgreSQL database).

Save changes.

6. Lastly, install the MySQL connector for Python via Web SSH (from the ~/ROOT folder):

pip install mysqlclient

2686-1-pip-install-mysqlclient

Note: To install the Python connector for a PostgreSQL database, get the psycopg2 module using pip:PATH=$PATH:/usr/pgsql-9.6/bin/ pip install psycopg2. If needed, modify the pgsql-9.6 part according to the used version of the PostgreSQL database server.

Run Wagtail CMS
After your database is prepared, you need to create the application database schema.

1. Enter the ~/ROOT folder and run the manage.py script.

cd ROOT

python manage.py migrate

2686-1-python-manage.py-migrate

2. Next, set the admin credentials for the Wagtail CMS control panel:

python manage.py createsuperuser

2686-1-wagtail-cms-create-admin-control-panel

In the dialog, you need to provide the Username, Email address and Password with confirmation.

3. To run the application using mod_wsgi, the wsgi handler should be created.
Enter the /var/www/webroot/ROOT directory and create the wsgi.py file with the following content:

import os,sys
virtenv = os.path.expanduser('~') + '/virtenv/'
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
   if sys.version.split(' ')[0].split('.')[0] == '3':
       exec(compile(open(virtualenv, "rb").read(), virtualenv, 'exec'), dict(__file__=virtualenv))
   else:
       execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
   pass
sys.path.append(os.path.expanduser('~'))
sys.path.append(os.path.expanduser('~') + '/ROOT/')
sys.path.append(os.path.expanduser('~') + '/ROOT/ROOT/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'ROOT.settings.dev'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

2686-1-wagtail-cms-wsgi-application

Save the newly created file.

4. Also, as we want to serve static content by our Apache Python server, we need to collect such content (run from the ~/ROOT folder):

python manage.py collectstatic

2686-1-serve-static-content-by-apache-python

After performing this action, all the static content of the current application is stored in the ~/ROOT/static directory.

5. That’s all! Now, you can click the Open in Browser button next to your environment with Wagtail CMS.

2686-1-open-wagtail-cms-in-browser-after-manual-installation

6. As a result, you will see the application’s welcome page.

2686-1-welcome-to-wagtail-cms-website-after-manual-installation

Click the here hyperlink to access the admin panel.

7. Log in using the credentials specified during the installation process.

2686-1-sign-in-to-wagtail-cms

Now, you can use the functionality of the admin panel to create pages and fill them with content.

2686-1-welcome-to-wagtail-cms

Jelastic PaaS provides you with great possibilities in deploying and serving Django-based Python applications such as Wagtail CMS. Get started easily at our Jelastic Paas platform.

SOURCEJelastic, Inc.