Getting Ubuntu 12.04 LTS, Django, and Heroku to all play nicely together
Personally, I used VMWare Workstation 8 to host my Ubuntu machine, so I will include some instructions for that as well.Part 1: Setup
Open: C:\ProgramData\VMware\VMware Workstation\config.ini (Windows 7)
Add the following:
prefvmx.minVmMemPct = "100"
mainMem.useNamedFile = "FALSE"
mainMem.partialLazySave = "FALSE"
mainMem.partialLazyRestore = "FALSE"
Note: This will prevent a long shutdown process for your vm.
- Install ubuntu 12.04 LTS
- After boot, login (command line), and enter the following:
- sudo shutdown -h 0
- Make sure settings of vm set cd / floppy to physical
- Install vmware tools & reboot (optional)
- sudo apt-get update && sudo apt-get dist-upgrade -y
- Reboot
sudo mv /etc/issue.backup /etc/issue
sudo mv /etc/rc.local.backup /etc/rc.local
sudo mv /opt/vmware-tools-installer/lightdm.conf /etc/init
Note: This gets you past the issues with VMWare Tools Easy Install
Part 2: Software Install
- sudo apt-get install build-essential linux-headers-$(uname -r) git vim python-setuptools python-virtualenv
- easy_install pip
- sudo apt-get install rubygems1.9.1 libopenssl-ruby1.9.1
- sudo gem install addressable
- sudo gem install heroku
- sudo gem install foreman
- ssh-keygen -t rsa
- mkdir -p ~/projects && cd ~/projects
- sudo apt-get install libpq-dev python-dev
- sudo apt-get install postgresql-server-dev-all
note: if psycopg2 still doesn't install later on, do sudo apt-get install libconfig8
Part 3: Django, Git, and Heroku
- mkdir hellodjango && cd hellodjango
- virtualenv venv --distribute
- source venv/bin/activate
- pip install django-toolbelt
- django-admin.py startproject hellodjango
- vim Procfile. Add the following:
- foreman start
- Test that your site is working by browsing to: localhost:5000 (or whatever the port is)
- pip freeze > requirements.txt
- vim .gitignore. Add the following:
web: gunicorn hellodjango.wsgi
venv
staticfiles
*.py[cod]
# C extensions
*.so
# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64
__pycache__
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
nosetests.xml
# Translations
*.mo
# Mr Developer
.mr.developer.cfg
.project
.pydevproject
- Edit hellodjango/settings.py. Add the following to the end:
# Parse database configuration from $DATABASE_URL
import dj_database_url
DATABASES['default'] = dj_database_url.config()
# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# Allow all host headers
ALLOWED_HOSTS = ['*']
# Static asset configuration
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
Edit hellodjango/wsgi.py. Replace it with:
from django.core.wsgi import get_wsgi_application
from dj_static import Cling
application = Cling(get_wsgi_application())
- git init
- git add .
- git commit -m "my django app"
- heroku create
- git push heroku master
- Log into heroku and rename your app
- Browse to yourappname.herokuapp.com
No comments:
Post a Comment