Documented by Kyle Bruder on Oct 09, 2020
Last updated on Feb 21, 2021
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.
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
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.
(lookaway-env) cp settings/production.py ~/production.py (lookaway-env) ln -s ~/production.py lookaway/settings.py
Add your website's domain name to the lists of allowed hosts in settings.py. Make sure it appears before 'test' in the list.lookaway/settings.py
... ALLOWED_HOSTS = [ 'www.example.com', 'testserver', ] ...
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.
(lookaway-env) python >>> from django.core.management.utils import get_random_secret_key >>> print(get_random_secret_key()) ny)4a70rj!xi6***************^1l!ryiy0u9kb7*3fd4462
Source: Humberto Rocha
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.~/.profile
export DJANGO_SECRET_KEY='<?>' export DJANGO_DATABASE_PASSWORD='<?>' export ES_FROM="email@example.com" export ES_HOST="mail.example.com" export ES_PORT="587" export ES_USER="<EMAIL USER>" export ES_PASS="<EMAIL PASSWORD>"
$ source ~/.profile
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.
(lookaway-env) mkdir media
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.
(lookaway-env) python manage.py migrate
Learn how to configure a Postgresql database and role for use with Lookaway CMS
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
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.
(lookaway-env) python manage.py createsuperuser
Congratulations, you have initialized Lookaway CMS!
Learn how to deploy Lookaway CMS onto a public webserver using Ubuntu 20.04 and PostgreSQL 10.