All posts All posts by this author Paper color Change page color Announcements

Mezzanine configuration with Apache + mod_wsgi on Ubuntu

Mezzanine is one of the best cms baised on Djnago.

Considering You have apache installed.

Create a virtualenv

$ virtualenv verenv

Activate virtualenv

$ source verenv/bin/activate

Install Mezzanine from PyPI

$ pip install mezzanine

Create a mezzanine project

$ mezzanine-project project_name
$ cd project_name

Create a database

$ python manage.py createdb

Collectstatic command for static files

$ python manage.py collectstatic

Write a wsgi script:

$ vi wsgi.py

Add following to the file

#!/usr/bin/env python

import os
import sys
import site

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
PROJECT_DIRNAME = PROJECT_ROOT.split(os.sep)[-1]

# path_to_virtualenv - replace this with the actual path
site.addsitedir('/path_to_virtualenv/verenv/lib/python2.7/site-packages')

sys.path.append(os.path.join(PROJECT_ROOT, ".."))

settings_module = "%s.settings" % PROJECT_DIRNAME
os.environ["DJANGO_SETTINGS_MODULE"] = settings_module

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

Apache configuration:

$ sudo vi /etc/apache2/sites-available/project_name

Add following to the file

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName project_name.localhost
    DocumentRoot /path_to_project/project/public_html
    WSGIDaemonProcess project_name.localhost python-path=/path_to_mezzanine_project/
    WSGIScriptAlias / /path_to_mezzanine_project/project_name/wsgi.py process-group=project_name.localhost
    <Directory /path_to_mezzanine_project/>
        <Files wsgi.py>
            Order deny,allow
            Allow from all
        </Files>
    </Directory>
    Alias /static/ /path_to_mezzanine_project/project_name/static/
    <Directory "/path_to_mezzanine_project/project_name/static/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride all
        Order deny,allow
        Allow from all
    </Directory>
    ErrorLog /path_to_project/project/logs/error.log
    LogLevel warn
    CustomLog /path_to_project/project/logs/access.log combined
    # path_to_project - replace with actual path
    # path_to_mezzanine_project - replace with actual path
</VirtualHost>

Install and enable mod_wsgi:

$ sudo apt-get install libapache2-mod-wsgi 
$ sudo a2enmod wsgi

Directory and file permission:First of all make sure all the directories exsists.

$ sudo chown www-data:www-data -R /path_to_mezzanine_project/project_name/ 
$ sudo chown www-data:www-data -R /path_to_project/project/logs/

Final step:

$ sudo a2ensite project_name
$ sudo service apache2 reload

Edit host file:

$ vi /etc/hosts

Add the following line to the file

127.0.0.1 project_name.localhost
Software Solutions