Install Django CMS on Ubuntu 12.04 with MariaDB, Gunicorn and Nginx

django_cmsIn this blog post we will show you how to install the Django CMS on a Ubuntu VPS with MariaDB, Nginx and Gunicorn  .

Django CMS is open source content management system based on the Web framework Django. Some of the main features include: Plugin-based, Pretty URLs, Permission management, Apps, Frontend-Editing, Analytics, Blog ..etc.


The following command will install all necessary packages

apt-get update
apt-get install -y python-software-properties python python-dev

Install the the latest version of Nginx

add-apt-repository ppa:nginx/stable
apt-get update && sudo apt-get install nginx

Install MariaDB and create a database.

apt-key adv --recv-keys --keyserver hkp:// 0xcbcb082a1bb943db
add-apt-repository 'deb precise main'
apt-get update
echo -e "Package: *\nPin: origin\nPin-Priority: 1000" | tee /etc/apt/preferences.d/mariadb
apt-get install mariadb-server libmariadbclient-dev
mysql -uroot -p
MariaDB [(none)]> CREATE DATABASE dcms;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON dcms.* TO 'dcmsuser'@'localhost' IDENTIFIED BY 'pa33W0rd';
MariaDB [(none)]> \q

Install pip

curl | python -

Create a virtualenv using pip

sudo pip install --upgrade virtualenv
mkdir -p ~/.virtualenvs/djangocms
virtualenv ~/.virtualenvs/djangocms
source ~/.virtualenvs/djangocms/bin/activate

Create a requirements.txt file with the following content

# Bare minimum

#These dependencies are brought in by django-cms, but if you want to lock-in their version, specify them

#Optional, recommended packages

Install django CMS

pip install --upgrade --download-cache=~/.pip-cache -r requirements.txt

Create your django CMS project

mkdir ~/projects
cd  ~/projects startproject mynewproject

Open the file ~/projects/mynewproject/mynewproject/ and add the following at the top of the file:

# -*- coding: utf-8 -*-
import os
gettext = lambda s: s
PROJECT_PATH = os.path.split(os.path.abspath(os.path.dirname(__file__)))[0]

Add your database details:

    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'dcms', 
        'USER': 'dcms',
        'PASSWORD': 'pa33W0rd',
        'HOST': '',
        'PORT': '',

Add the following apps to the INSTALLED_APPS.


Add the following lines to the MIDDLEWARE_CLASSES list.

    # Uncomment the next line for simple clickjacking protection:
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',

Add the following at the end of the file:


Change STATIC_ROOT and MEDIA_ROOT directives to:

STATIC_ROOT = os.path.join(PROJECT_PATH, "static")
STATIC_URL = "/static/"

MEDIA_ROOT = os.path.join(PROJECT_PATH, "media")
MEDIA_URL = "/media/"

Modify the TEMPLATE_DIRS directive:

    # The docs say it should be absolute path: PROJECT_PATH is precisely one.
    # Life is wonderful!
    os.path.join(PROJECT_PATH, "templates"),

Add at least one template to CMS_TEMPLATES

    ('template_1.html', 'Template One'),
    ('template_2.html', 'Template Two'),

Limit to English

    ('en', 'English'),

Finally save the file.

Define routes for our project

Open mynewproject/mynewproject/ file and replace the content with the following

from django.conf.urls.defaults import *
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.conf import settings


urlpatterns = patterns('',
  url(r'^admin/', include(,
  url(r'^', include('cms.urls')),
if settings.DEBUG:
    urlpatterns = patterns('',
    url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
    url(r'', include('django.contrib.staticfiles.urls')),
) + urlpatterns

Create templates

Create a new directory templates

mkdir ~/projects/mynewproject/templates

Open your favorite editor and create the following files:


{% load cms_tags sekizai_tags %}
      {% render_block "css" %}
      {% cms_toolbar %}
      {% placeholder base_content %}
      {% block base_content %}{% endblock %}
      {% render_block "js" %}


{% extends "base.html" %}
{% load cms_tags %}

{% block base_content %}
  {% placeholder template_1_content %}
{% endblock %}


{% extends "base.html" %}
{% load cms_tags %}

{% block base_content %}
  {% placeholder template_2_content %}
{% endblock %}

Initialize the database and create a new superuser

python syncdb --all
python migrate --fake

Check if everything is set up correctly

python cms check

If you see “Installation okay”, it means everything is set up correctly.

Collect  static files

cd ~/projects/mynewproject
./ collectstatic

Install and configure gunicorn

pip install gunicorn

create a new configuration file (~/.virtualenvs/djangocms/ as follows

command = '~/.virtualenvs/djangocms/bin/gunicorn'
pythonpath = '~/projects/mynewproject'
bind = ''
workers = 3
user = nobody

Start the gunicorn with the following command:

cd ~/projects/mynewproject && gunicorn -c ~/.virtualenvs/djangocms/ mynewproject.wsgi

Configure Nginx

Create a new nginx virtual host

vim /etc/nginx/sites-available/
server {
 listen       80;

    location /static/ {
        alias /<your_username>/projects/mynewproject/static/;

    location / {
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_connect_timeout 10;
        proxy_read_timeout 10;
        proxy_pass http://localhost:8011/;

ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/
/etc/init.d/nginx restart

That’s it. Now open your browser and navigate to your domain.

For more info about the Django CMS please go to:

Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to install this for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

1 thought on “Install Django CMS on Ubuntu 12.04 with MariaDB, Gunicorn and Nginx”

  1. Hello,

    Thank you for Howto.

    but what is with admin panel? The admin panel come without style. Is there another folder which must be have instuction of location, root?


Leave a Comment

To prove you are human please solve the following *