Archives

Categories

Install django CMS on WebFaction

I’m testing out django CMS for a small personal site, bobtiki.me, and installing it on my WebFaction hosted server. I’m writing down the steps, so you don’t have to! (And by “you,” I mean “future Mark who has forgotten these steps.”)

I’ve had a great experience with WebFaction — they’re both inexpensive and reliable. If you’d like to give them a try, please use this affiliate link to sign up for a free trial, and try installing for yourself.

Create a new website

On my.webfaction.com, log into your account and go to:

  • Domains / Websites > Websites > Add new website
  • Name: my_cms (or whatever you prefer here)
  • Status: Enabled
  • Security: Normal website (http) for this tutorial, but I highly recommend moving to https for all sites soon. It’s outside of the scope of this article, but I’m eyeing the free Let’s Encrypt for getting certificates.
  • Domains: example.com (or whatever your domain is)

Then click the Add an application button, then Create a new application, and in the pop-over form:

  • Name: my_cms (I like to keep the application name the same as the site name, unless I have multiple applications handling one site)
  • App category: mod_wsgi
  • App type: mod_wsgi 4.5.2/Python 3.5 (latest versions as of this writing)
  • Open port: leave unchecked
  • URL: should be pre-filled with http://example.com/
  • Save

Once saved, click Save again to finish creating the new website.

We’re going to need a database for the site, so while we’re here in the WebFaction control panel, let’s create one:

  • Go to Databases > Databases > Add new database
  • Name: my_cms
  • Database type: PostgreSQL
  • Encoding: Unicode
  • Database owner: Create a new postgresql user, and enter your user and password combo here.
  • Add-ons: leave all unchecked
  • Save

Yay! Now visit your domain in your browser and you should see something like this:

Remove htdocs

Now that we’ve seen /webapps/my_cms/htdocs powering the test wsgi page, its usefulness has passed, so delete the directory.

For file management on my server, I’m using the Mac app Transmit to connect over SFTP. I’m going to assume that if you prefer to manage your files in the command line, you know how to do that.

Virtual environment

First, ssh into your web server and change to the site’s webapp directory:

Then, let’s make a virtual environment for the new Django site to run under. I’m calling mine my_cms (I know, not very imaginative).

Since we are using Python 3.5, virtualenv and virtualenvwrapper are no longer needed. Python 3.3 and later include its own virtual environment tool, venv.

We want Python 3.5, so we’ll run that version of pyvenv to create the virtual environment, then activate it:

When you see the venv name in parentheses in front of your prompt, you know it’s activated.

I really miss the workon my_cms style activation that virtualenvwrapper provided. TODO: Research replacement for use with Python 3.3+’s venv.

Even though even though pyvenv defaults to the include-system-site-packages key set to false, there is a global site customization policy in WebFaction’s system Python installations, which automatically includes some other packages, and venv isn’t able to ignore it. To work around this, create an empty file named sitecustomize.py in your environment’s lib/python3.5 directory, like so:

The file doesn’t need to have any contents; its very presence performs the override. Now you shouldn’t see the system site packages when your environment is activated.

First, make sure the version of pip inside your virtual environment is up to date:

Then, install the django CMS installer:

Create a new directory to work in, and cd into it:

Run the installer to create a new django CMS project called my_cms:

Configure Apache and WSGI

We are now ready to configure Apache to serve our Django project. In order to do this, we’ll need to modify the contents of the Apache configuration file, ~/webapps/my_cms/apache2/conf/httpd.conf so that it knows to run our django-cms and to activate the virtual environment. Copy the original file to a backup (just in case), and make these changes:

Now, restart the Apache server:

…and you should see the django CMS example home page.

django CMS

Bibliography

Helpful information came from these articles and forum posts:

If you have comments, please share them with me on Twitter or Facebook.

You should check out my podcast about movie magic and VFX: The Optical.