Installing Mezzanine on Ubuntu with Apache and mod_wsgi

Although there are many advantages to installing Mezzanine using Python’s virtual environment, I decided against it. I already have Django installed on Apache using mod_wsgi, so my Ubuntu install is already primed. Although I followed the basic steps as discussed in a previous post (Setting up Django with Apache and mod_wsgi on Ubuntu 11.10), there were a bit more steps involved with setting up Mezzanine – especially as it relates to how and where to serve static files.

This article assumes that you already have Python installed on Ubuntu (and Apache). For information on installing Apache, mod_wsgi, and pip, read my post: Setting up Django with Apache and mod_wsgi on Ubuntu 11.10.

Install Mezzanine

First, we’ll use pip to install Mezzanine.

pip install mezzanine

mod_wsgi Configuration File

Next we are going to create mod_wsgi configuration file. I create all of my sites under /srv/www, but you may opt to use the traditional /var/www.

sudo mkdir /srv/www/mycms
sudo mkdir /srv/www/mysite/apache
sudo vi /srv/www/mysite/apache/apache.wsgi

The configuration file is basically the same as the configuration for any Django site:

import os 
import sys 
 
path = '/srv/www' 
if path not in sys.path: 
    sys.path.insert(0, '/srv/www/mysite') 
    sys.path.append('/srv/www/mysite/mysite/') 
 
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' 
 
import django.core.handlers.wsgi 
application = django.core.handlers.wsgi.WSGIHandler()

Virtual Host

Next we’ll set up the virtual host.

<virtualHost *:80> 
    ServerName mysite.local 
    DocumentRoot /srv/www/mysite/mysite 
 
    AliasMatch ^/([^/]*\.css) /srv/www/mysite/mysite/static/css/$1 
   # create alias for media and static directories
    Alias /media/ /srv/www/mysite/mysite/media/ 
    Alias /static/ /srv/www/mysite/mysite/static/ 
 
    <Directory /srv/www/mysite/mysite/static> 
        Order deny,allow 
        Allow from all 
    </Directory> 
 
    <Directory /srv/www/mysite/mysite/media> 
        Order deny,allow 
        Allow from all 
    </Directory> 
 
    <Directory /srv/www/mysite/mysite> 
        Order allow,deny 
        Allow from all 
    </Directory>
 
    WSGIDaemonProcess mysite.local processes=2 threads=15 display-name=%{GROUP} 
    WSGIProcessGroup mysite.local 
 
    WSGIScriptAlias / /srv/www/mysite/apache/apache.wsgi 
 
</VirtualHost>

We set up an alias for /static/ and /media/ so that we can serve static files from within the Mezzanine (mysite) project files.

Create Mezzanine Project

Next we’ll create a Mezzanine project.

cd /srv/www/mysite
mezzanine-project mysite
cd mysite

Create Database

By default, Mezzanine creates a sqlite database. I learned this after I created the database (and after I received the error: DatabaseError at/ attempt to write a readonly database). I want to use a PostgreSql database, so I edited the Mezzanine settings file (/srv/www/mysite/mysite/local_settings.py)

?View Code PYTHON
DATABASES = { 
    "default": { 
        "ENGINE": "django.db.backends.postgresql_psycopg2", 
        # DB name or path to database file if using sqlite3. 
        "NAME": "mysite", 
        "USER": "postgres", 
        "PASSWORD": "mypassword", 
        # Set to empty string for localhost. Not used with sqlite3. 
        "HOST": "localhost", 
        # Set to empty string for default. Not used with sqlite3. 
        "PORT": "", 
    } 
}

Although, the comment says to set an empty string for localhost, I receive a connection error when I attempted to run the createdb command (Peer authentication failed for user). You need to create a database before you continue. You can choose to create the database using a tool like pgAdmin or just create from the command line:

su postgres (and enter a password)
psql
CREATE DATABASE mobilepebbles WITH OWNER postgres;
\q (quit)
exit (go back to normal user)

Now we can create run the createdb command to create the tables needed for Mezzanine.

python manage.py createdb --noinput

Activate the Site

Now we have activate the site.

sudo a2ensite mysite

And set up the host entry (vi /etc/hosts)

127.0.0.1      mysite.local

Now reload Apache.

sudo /etc/init.d/apache2 reload

Now navigate to the site:

http://mysite.local

The default content is displayed, but there is no styling. We have to modify the theme.

Be Sociable, Share!

Checkout My New Site - T-shirts For Geeks