Django CMS Installation to the Cloud

18

3054-1-django-cms-logoDjango CMS is a free open-source content management system based on the Django web framework, which ensures a quick integration of the databases and new modules. Django CMS helps to simplify the process of creating complex websites due to its intuitive and easy-to-learn drag and drop interface. Simultaneously, it is powerful and expandable enough to satisfy the most demanding content editors.

Today, we’ll overview the steps required to automatically or manually install the Django CMS solution to the cloud with Jelastic PaaS.

Django CMS Automatic Installation

You can automatically get a preconfigured ready-to-work Django CMS instance up and running within minutes using the Jelastic PaaS Marketplace.

1. Log in to your Jelastic PaaS account and click the Marketplace button at the top of the dashboard.

3054-1-jelastic-paas-marketplace-button

2. Search for the DjangoCMS solution in the opened window.

3054-1-marketplace-installation-django-cms

Hover over the located package and click Install.

3. Within the appeared installation frame, you can adjust the following fields:

  • Environment – set an environment name;
  • Display Name – define a preferable alias;
  • Region – select an environment region (if multiple are available).

3054-1-django-cms-in-jelastic-paas-marketplace

Proceed with the Install button.

4. That’s it! In just a few minutes your Django CMS application will be installed.

3054-1-django-cms-installed

Use the information within the pop-up to access your Django CMS home and admin panel pages.

Django CMS Manual Installation

You can deploy Django CMS manually with the help of the following step-by-step instruction and take the complete control over the process.

Let’s start by creating an environment for Python applications hosting. To do this, follow the next steps:

1. Click the NEW ENVIRONMENT button.

3054-1-create-new-environment

2. Navigate to the Python programming language tab, where the Apache application server will be selected automatically. State the resource limits, choose the region (if available) and enter the name (e.g., django-cms) for your environment.

3054-1-apache-python-environment

Note:

  • Currently, the Django CMS does not support Python 3.7, so select the version appropriately;
  • Django CMS requires a database; herewith, you can use:
    • SQLite – is implemented by default and does not require any additional configurations (data is stored locally on the same container as your application); this solution is suitable for the development and testing purposes;
    • external SQL database (e.g., MySQL or PostgreSQL) – is a secure and reliable option to be used for the production environments.

Finally, click Create at the bottom right corner of the frame.

3. Just in a minute, your environment will appear at the dashboard.

3054-1-django-cms-environment

Now, you can install Django CMS from scratch or deploy your existing application into the environment. We’ll check both these options one-by-one.

Install Django CMS
1. Connect to your application server via Web SSH:

3054-1-django-cms-web-ssh

2. You should create an isolated virtual Python environment for your application, using the virtual environment tool, which allows managing projects’ dependencies independently without administrator privileges:

virtualenv virtenv

3054-1-python-virtual-environment

3. Activate and switch to the newly created virtual environment by executing the next command:

source virtenv/bin/activate

3054-1-django-cms-virtual-environment

4. Install the Django CMS installer using the pip package manager:

pip install djangocms-installer

3054-1-django-cms-installer

Wait a minute for the operation to be completed.

5. Next, remove the pre-installed application and create a new Django CMS application:

rm -rf ROOT

djangocms -p . ROOT -s

Tip: You can read more about Django CMS installer arguments at the official documentation. For example, use the -w option to enable wizard mode installation and manually define various specific settings.

3054-1-remove-django-cms-application

6. Edit the mod_wsgi module (the /var/www/webroot/ROOT/wsgi.py file) by replacing its content with the lines below:

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/')

os.environ['DJANGO_SETTINGS_MODULE'] = 'ROOT.settings'

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

3054-1-mod-wsgi-module

Save the changes.

7. Adjust the next parameters in the /var/www/webroot/ROOT/settings.py configuration file:

ALLOWED_HOSTS = ["{envDomain}"]

MEDIA_ROOT = os.path.join(DATA_DIR, 'ROOT', 'media')
STATIC_ROOT = os.path.join(DATA_DIR, 'ROOT', 'static')

STATICFILES_DIRS = (
	os.path.join(BASE_DIR, 'ROOT', 'static_local'),
)
Note: The ALLOWED_HOSTS option contains a list of strings representing the domain names, which this Django site can serve (django-cms.jelastic.com in our case). Also, can be set as * to match any host.If using an external database, the connection details should be specified within the DATABASES section, where:

  • ENGINE – database type (django.db.backends.mysql for MySQL or django.db.backends.postgresql_psycopg2 for PostgreSQL);
  • NAME, USER, PASSWORD – database account credentials to connect;
  • HOST – database hostname (from the email received after database creation);
  • PORT – database port (3306 for MySQL or 5432 for PostgreSQL).

3054-1-settings-py-configuration-file

Don’t forget to Save the changes.

8. Create new sub-directories for the static/media content and run the synchronization of resources:

mkdir ROOT/static_local

mkdir ROOT/media

python manage.py collectstatic

3054-1-python-manage-py-collectstatic

9. That’s all! Now, you can access your environment by clicking Open in Browser.

3054-1-open-django-cms-in-browser

Within the opened page log in to the admin panel using the default admin/admin credentials.

3054-1-successful-installation-of-django-cms

Now you can immediately start working by creating your first page with Django CMS.

Deploy Existing Django Application
In case you have already the previously built and packaged Django application, the deployment procedure can be performed just in a few steps.

Note: If configuring own deployment archive, please ensure your Django package contains the following files in its 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 using the mod_wsgi for Apache.

1. Upload your application to the deployment manager, for example:

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

3054-1-upload-django-cms-to-the-deployment-manager

2. Deploy your Django application into the environment with the Apache Python application server.

3054-1-deploy-django-application

3. In a minute (after successful deployment), click the Open in Browser button for your environment to access the application.

3054-1-open-django-environment-in-browser

4. Done! Your Django application is up and running in just a few minutes!

With our example, you’ll be redirected to the Django CMS admin panel, where you should log in with the default jelastic/jelastic credentials to start working.

3054-1-django-cms-admin-panel

As you can see, it’s quite easy to deploy Django-based applications with the Jelastic PaaS Python hosting. Try it yourself with a free trial at our Jelastic PaaS platform.