Skip to content

Instantly share code, notes, and snippets.

@tjoskar
Created June 26, 2013 12:06
Show Gist options
  • Save tjoskar/5866888 to your computer and use it in GitHub Desktop.
Save tjoskar/5866888 to your computer and use it in GitHub Desktop.

Setup django using apache2 and MySQL (Ubuntu)

Install mod_wsgi for apache2.

$ sudo apt-get install libapache2-mod-wsgi

Install pythons mysql connector.

$ sudo apt-get install python-mysqldb

Install Django, see https://www.djangoproject.com/download/ for latest version, or if you have pip:

$ pip install django

Create a wsgi file:

import os, sys
root = os.path.join(os.path.dirname(__file__), 'PATH_TO_PROJECT_ROOT')  # Eg. /srv/project/current/
sys.path.insert(0, root)
sys.path.append('PATH_TO_PROJECT')  # Eg. /srv/project/current/django_project
os.environ['DJANGO_SETTINGS_MODULE'] = 'PROJECT_NAME.settings'  # Eg. django_project
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Create a virtual host (see: https://gist.github.com/tjoskar/5517266 for mor info) Add, however, this line:

WSGIScriptAlias / /PATH_TO_YOUR_WSGI_FILE_YOU_CREATE_OBOVE

Enable the new vhost and reload apache :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment