Setting up Django and Wordpress together

June 20, 2013

Going from a fresh Ubuntu install to a functioning django and wordpress site is pretty simple. I mostly borrowed the instructions from here.

Before you begin, you should go to your domain name provider and set an A (address) record for your domain name to your instance's IP address. If you don't have a domain name, buy one. Unless you have a really common name, or are building, domain names are cheap and will only increase in demand in the future. I'm using as the django site, and as the wordpress site.


Install dependencies. I use a standard apache/mysql/python stack:

sudo apt-get install apache2 libapache2-mod-wsgi python python-pip
mysql-server python-mysqldb
pip install django

Create your Django project somewhere:

cd /usr/local/src/
sudo startproject myproject

Next, create an apache config for your main site:

touch /etc/apache2/sites-enabled/

and put this in it:

<VirtualHost *:80>
WSGIScriptAlias / /var/www/apache/django.wsgi
<Directory /var/www/apache>
Order deny,allow
Allow from all

Create a wsgi file:

touch /var/www/apache/django.wsgi

and put this in it:

import os, sys  
root = os.path.join(os.path.dirname(__file__), '/usr/local/src')  
sys.path.insert(0, root)  
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'  
import django.core.handlers.wsgi  
application = django.core.handlers.wsgi.WSGIHandler()

Set some permissions:

chmod o+r /var/www/apache/django.wsgi  
chmod o+rx /var/www/apache  
chmod o+rx /usr/local/src

Restart apache:

sudo /etc/init.d/apache2 reload  
sudo /etc/init.d/apache2 restart

Now, navigate to if everything went ok, you should see the Django success page. If not, check your apache logs and make sure your DNS records are correct and have propagated.


Next up is wordpress on a subdomain. Follow the directions here.

After that, we still need to configure apache for this site:

touch /etc/apache2/sites-enabled/

Put this in it:

<VirtualHost *:80>  
DocumentRoot /var/www/wordpress  

Restart apache again. And that's it. Visit to set up wordpress. Make sure to set WordPress Address and Site Address (in settings) to, so your links are correct.