Deploying a Django Site

From OCS Support Wiki

Jump to: navigation, search

Contents

Introduction

This guide will show you how to setup a Django site on the OCS Solutions shared hosting servers.

Before You Start

All OCS Solutions shared hosting servers are intended to be production servers, and we do not recommend nor support active development on applications in our production environment. Ideally, you should develop and work on your applications locally on your computer, then upload the project in production-ready chunks for deployment. We must maintain this policy to ensure the high level of availability and security our shared hosting service provides.

Deploying Your Django Site

Preparing Your Django App Folder

We recommend you store your Django projects in the django_apps folder in your home directory (NOT in your public_html folder). You can make this folder via FTP, or via SSH with the command:

mkdir ~/django_apps

Once this is done, create a folder for your Django site. In this case, we'll call it mysite, so the full path to the Django site will be ~/django_apps/mysite.

Creating the WSGI Interface

Once the site is uploaded, create a file called django.wsgi in your public_html folder with the following contents (replacing the word user with your cPanel/Webmin username):

NOTE: These are NOT commands to run, rather the contents of django.wsgi!

import os
import sys

sys.path.append('/home/user/django_apps/mysite')

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

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

Save the file and make sure it has 0755 permissions. You can do this via SSH by running:

chmod 0755 ~/public_html/django.wsgi

Apache Directives

The next step must be completed by our technical support staff. Open a ticket and tell us to add the necessary directives for your Django application. In the ticket, you must specify the full path to your Django app. This would be similar to:

/home/user/django_apps/mysite

(replace user with your cPanel/Webmin user, and mysite with the appropriate folder name)

We will add the necessary directives and reply to the ticket when done. Once this is complete, your Django site will be live!

Important Note About Apache Directives

You do NOT have to open a ticket each time you deploy your Django app. This is only necessary once per site.