Django MEZZANINE Blog Setup


In the previous post, I wrote how to set up django zinnia blog.
However, django-zinnia-blog documentation is not really intended for django beginners and you have read the source to know how it works.
I only know the basic, I could not properly override urls and templates, because it seemed django-zinnia-blog apps depend on each other and it was difficult to just deploy the app I want from it.
Mezzanine is a CMS but has a blog functionality as well. And most importantly it has very rich documentation. It's got even FAQ! It also explains how to override templates.:) I think it comes with caching functionality, too because it performs a lot faster than zinnia with demo setup.
A following note is how to have mezzaine running on arch linux with nginx and postgresql and uwsgi. I choose arch linux, because it is the simplest distribution I know and it's bleeding edge which I think makes the OS more secure. Systemd works wonderfully as well. Nginx and postgresql are chosen just because I feel they are a lot lighter than other alternatives. I alway choose uwsgi because it is simple enough and people say it performs the best among python application servers.

1. Nesessary packages. (from Arch linux repository and pip)
pacman -S python-pip libjpeg-turbo gcc nginx postgresql
pip install mezzanine
pip install uwsgi

2. DB (btrfs)
su - postgres
initdb --locale en_GB.UTF-8 -E UTF8 -D '/var/lib/postgres/data/'
chattr +C /var/lib/postgres/data

su -
systemctl start postgresql
systemctl enable postgresql

su - postgres
createuser --interactive
createdb myblogdb

psql
GRANT ALL ON DATABASE myblogdb TO root;
\q

3. uwsgi
mkdir -p /etc/uwsgi/vassals

vim /etc/uwsgi/emperor.ini
#--------------------------#
[uwsgi]
emperor = /etc/uwsgi/vassals
uid = http
gid = http
#--------------------------#

vim /etc/systemd/system/emperor.uwsgi.service
#--------------------------#
[Unit]
Description=uWSGI Emperor
After=syslog.target

[Service]
ExecStart=/usr/bin/uwsgi --ini /etc/uwsgi/emperor.ini
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/bin/kill -INT $MAINPID
Restart=always
Type=notify
StandardError=syslog
NotifyAccess=all
KillSignal=SIGQUIT

[Install]
WantedBy=multi-user.target
#--------------------------#

4. MEZZANINE
mkdir /opt/mezzanine
cd /opt/mezzanine
mezzanine-project myblog
cd myblog

vim myblog/local_settings.py
#--------------------------#

DATABASES = {
    'default': {
    'ENGINE': 'django.db.backends.postgresql',
    'NAME': 'myblogdb',
    'USER': 'root',
    'HOST': 'localhost',
    'PORT': '5432',
    }
}
#--------------------------#

cp -p /usr/lib/python3.5/site-packages/mezzanine/utils/html.py /usr/lib/python3.5/site-packages/mezzanine/utils/html.py.ori

vim /usr/lib/python3.5/site-packages/mezzanine/utils/html.py
#--------------------------#
remove ,HTMLParseError from the forth line.
#--------------------------#

mkdir -p static/media
python manage.py collectstatic
python manage.py migrate

5. nginx conf for mezzanine. (Example. I recommend going full ssl.)
vim /opt/mezzanine/myblog/myblog_nginx.conf
#--------------------------#
upstream django {
    server 127.0.0.1:8001;
}

server {
    listen 80;
    server_name 0.0.0.0;
    charset utf-8;

    location /static {
        alias /opt/mezzanine/myblog/static;
    }

    location / {
        uwsgi_pass django;
        include /etc/nginx/uwsgi_params;
    }
#--------------------------#

mkdir /etc/nginx/sites-enabled/
ln -s /opt/mezzanine/myblog/myblog_nginx.conf /etc/nginx/sites-enabled/

6. uwsgi conf for mezzanine

vim /opt/mezzanine/myblog/myblog_uwsgi.ini
#--------------------------#
[uwsgi]
chdir = /opt/mezzanine/myblog/
module = myblog.wsgi
master = true
processes = 4
socket = 127.0.0.1:8001
#--------------------------#

ln -s /opt/mezzanine/myblog/myblog_uwsgi.ini /etc/uwsgi/vassals/

7. http directive main nginx conf.
vim /etc/nginx/nginx.conf
#--------------------------#
include /etc/nginx/sites-enabled/*;
#--------------------------#

8. change local_settings.py to
DEBUG = False
ALLOWED_HOSTS = ['*']

9. Create admin user for the django project, resync the db just in case.
python manage.py createsuperuser
python manage.py migrate

10. start service
systemctl restart nginx
systemctl restart postgresql
systemctl restart emperor.uwsgi
systemctl reenable nginx
systemctl reenable postgresql
systemctl reenable emperor.uwsgi

Advertisements
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: