The IJC Digital Blog

Posted by: Matt Mansour 8 years, 6 months ago (1 comment)

The open source Content Management System, Mezzanine, is a very well built piece of software. Likewise, Webfaction is a great web hosting company, especially for Django projects on a small hosting budget. Webfaction makes hosting Django powered web sites relatively simple. However, installing Mezzanine at Webfaction with virtualenv is not the most intuitive process. Here is how I did it. And you are looking at the results now, on this Mezzanine powered site:

First, In Webfaction's panel ( create a domain name:   Domains -> Add Domain. 

Then create a new WebFaction application with a "Type:" of "mod_wsgi 3.2/Python 2.6". Use the Add Icon at the bottom of the app list.  I named my application "mezzanine_server".

Then create a new WebFaction website and associate the domain name with the new mezzanine_server application. Give it a name, at least one domain, and set it to use the mezzanine_server application. For the websites's URL path use "/".

We will need to create two more applications: One for Django's admin media. One for the public facing site's static media. But first, let's get Mezzanine installed in a virtual environment, and create the project.

SSH into your webfaction machine and install virtualenv if it's not already installed. Then create the virtual environment location for mezzanine. I created a directory called /envs/ for all my environments. So to set up the mezzanine environment I ran the command:

virtualenv --distribute ~/envs/mezz --no-site-packages

Then CD into the bin of your newly created environmant and install mezzanine

$ cd ~/envs/mezz/bin
$ source activate $ pip install -U mezzanine

And create your mezzanine project

$ mezzanine-project ~/webapps/project_name

Then run your project with the usual Django steps

$ cd project_name
$ python createdb --noinput

If we were working locally we'd "runserver" and view the site at localhost:8000. In this case we need to finish configuring your machine at Webfaction so your mezzanine powered website can be found at the domain you configured earlier.



Remove or comment out the following lines

DocumentRoot /home/my_account/webapps/mezzanine_server/htdocs
<Directory /home/my_account/webapps/mezzanine_server/htdocs>

Here is how my httpd.conf file basically looks.

ServerRoot "/home/my_account/webapps/mezzanine_server/apache2"

LoadModule dir_module        modules/
LoadModule env_module        modules/
LoadModule log_config_module modules/
LoadModule mime_module       modules/
LoadModule rewrite_module    modules/
LoadModule setenvif_module   modules/
LoadModule wsgi_module       modules/
LoadModule alias_module      modules/

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog /home/my_account/logs/user/access_mezzanine_server.log combined
#DocumentRoot /home/my_account/webapps/mezzanine_server/htdocs
ErrorLog /home/my_account/logs/user/error_mezzanine_server.log
KeepAlive Off
Listen 51370
MaxSpareThreads 3
MinSpareThreads 1
ServerLimit 1
SetEnvIf X-Forwarded-SSL on HTTPS=1
ThreadsPerChild 5
#WSGIDaemonProcess mezzanine_server processes=5 python-path=/home/my_account/webapps/mezzanine_server/lib/python2.6 threads=1
WSGIDaemonProcess mezzanine_server processes=5 python-path=/home/my_account/envs/mezz/lib/python2.6 threads=1

WSGIPythonPath /home/my_account/webapps:/home/my_account/envs/mezz/lib/python2.6
WSGIScriptAlias / /home/my_account/webapps/mezzanine_server/project_name/deploy/project_name.wsgi

#    AddHandler wsgi-script .py

Edit your wsgi file. Mine looks like this:

import os
import sys

sys.stdout = sys.stderr

from site import addsitedir

from os.path import abspath, dirname, join
from django.conf import settings

os.environ["DJANGO_SETTINGS_MODULE"] = "my_project.settings"
sys.path.insert(0, join(settings.PROJECT_ROOT, "apps"))

from django.core.handlers.wsgi import WSGIHandler
application = WSGIHandler()

Restart apache


If things went smoothly you will see your Mezzanine powered website at the domain, with no stylesheets and images. If things did not go smoothly the apache logs are your friend, and can be found here at Webfaction:


Now we will create the last two applications mentioned above. These will fix the missing admin media and static media.

First let's create the app that pulls in admin media to your website. In the Webfaction panel create a "Symbolic link to static-only app". I called mine "mezzanine_admin_media.". In the "Extra Info" field add the path to your static media. Mine looks something like this:  "/home/my_account/envs/mezz/lib/python2.6/site-packages/grappelli_safe/media"

Second, repeat the steps above to create another app that pulls in the media for your public facing website. I called mine "mezzanine_static_media.".  My "Extra Info" looks something this: "/home/my_account/webapps/mezzanine_server/my_project/my_theme/media".  I created my own theme for the look and custom admin functionality for this site. You can learn about creating custom themes in the Mezzanine documentation.

In the webfaction panal associate both apps with your website at "Domains/Website".

In the "URL Path" field use "/media" for the "mezzanine_admin_media" app, and use "/site_media" for your static app. Restart apache and you should be all set.

It is a good idea for SEO purposes to redirect the www version of your domain to the nonwww version of your domain. That is done by creating one more app and editing its .htaccess file. Refer to the webfaction documentation.

Happy Coding


Current rating: 4.4