Lookaway CMS Initialization - Ubuntu 20

Documented by kbruder tech✞ᵀᵀᴹ on Oct 09, 2020
Last updated on Feb 21, 2021

Ubuntu Server 20 logo


Initialize all of the modules, files, and configurations for a fresh production Lookaway CMS installation. Before using the commands in this guide, be absolutely sure you are logged in as lookaway and have activated the virtual environment or strange things may happen to your system. Also make sure that your working directory is the base directory for Lookaway CMS.

  1. Logs Directory

    Create a new directory called "logs" in lookaway's home directory. This is where Lookaway CMS and Nginx will write logs for debugging.

    (lookaway-env) mkdir ~/logs

  2. Production Settings

    Lookaway CMS comes with 2 settings templates. One is for Development and one is for Production. First copy the PRODUCTION template to a safe place like lookaway's home directory. Next, link the new file to Lookaway's settings.py.

    Tip: When in doubt, refer to Django's official deployment checklist (see below).

    Caution: It is very important not to run the development server on a production system. It may provide attackers with information that can be used to compromise your entire system and possibly your network as well.

    (lookaway-env) cp settings/production.py ~/production.py
    (lookaway-env) ln -s ~/production.py lookaway/settings.py

    🌐 Deployment checklist | Django documentation | Django

  3. Your Domain

    Add your website's domain name to the lists of allowed hosts in settings.py. Make sure it appears before 'test' in the list.


  4. Django Secret Key

    Every Django installation needs a unique string known as the Django Secret Key. When starting a new project using the commands included with the Django python module, this is done for you automatically. The Lookaway CMS repository does not include a key so you must create one. Open a Django/Python shell and manually call the method from the Django module.

    Caution: Do not let ANYONE learn this key. Anyone who has this key can gain complete control of your site.

    (lookaway-env) python
    >>> from django.core.management.utils import get_random_secret_key
    >>> print(get_random_secret_key())

    Source: Humberto Rocha

  5. Environment Variables

    Because of the sensitivity of the Django Secret Key and the Lookaway CMS database password, we need to store them outside of the git repository. The best place is in lookaway's ".profile" file which will execute when the "su" command is called by Gunicorn to become the lookaway service user. Modify .profile and append the following lines to the bottom of the file. Replace <?> with the appropriate keys. Once the file is written, source the file to update your environment variables using the command below.

    export DJANGO_SECRET_KEY='<?>'
    export ES_FROM="support@example.com"
    export ES_HOST="mail.example.com"
    export ES_PORT="587"
    export ES_USER="<EMAIL USER>"

    $ source ~/.profile

  6. Lookaway Media Directory

    All of the files uploaded by members of Lookaway CMS need to be stored somewhere. It doesn't really matter what medium is used to store the data. For example, it can be a Network File System, a physical hard drive, or a cloud storage solution. What does matter is that the storage is mapped to a directory called "media" in the base lookaway directory.

    Tip: It is best to mount a filesystem separate from the OS to this directory.

    (lookaway-env) mkdir media

  7. Database Migration

    Since we are initializing a new installation and a empty database has been created, Django needs to create the database schema before the site can run. If you have not yet created a database and role for Lookaway CMS, see the link below. Once again, Django has us covered here. Use the migrate command to migrate the database.

    Caution: Using this command after pulling an update from the master repository or a development branch can result issues that need to resolved in various ways. We will do our best to document as many of these possibilities as we can. If you run into a problem, check Stack Overflow. There are a lot of answers on there.

    (lookaway-env) python manage.py migrate

    Lookaway CMS Database Configuration - Postgresql 10

    Learn how to configure a Postgresql database and role for use with Lookaway CMS

    🌐 Stack Overflow

  8. Lookaway Static Files

    Unlike Django's development server, in production, Django does not serve static files. Instead, Nginx will perform this task. However, since static files are included with Lookaway CMS and the Django admin console, they need to be copied to a directory that Nginx can safely access. Fortunately, Django provides a command to handle this task, which must be done whenever any of the static files are modified or are newly created.

    (lookaway-env) python manage.py collectstatic

  9. Super User

    Now that everything is in place and we have a fully built database we can create the first member: You! That's right! if you made it this far, your are the site admin. You can always find someone else to fill the role of Site Admin, but it is important to have as few "superuser" accounts as possible . A "superuser" is the unrestricted account in Django that is used by the site admin.

    Tip: If you have more than one site administrator, do not share accounts. Instead, create one account per admin with unique strong passwords.

    (lookaway-env) python manage.py createsuperuser


Congratulations, you have initialized Lookaway CMS!

Referenced by

Lookaway CMS Production Server - Ubuntu 20

Learn how to deploy Lookaway CMS onto a public webserver using Ubuntu 20.04 and PostgreSQL 10.