This is a guide to setup a new installation of Django and Postgres, running in an Ubuntu 22.04 Vagrant Box. Install Vagrant and Virtualbox before proceeding.
Clone Github repository to your local development machine:
git clone [email protected]:hamishcomau/vagrant-django.git
Search for yourapp
in all files and replace with your preferred project name.
vagrant up
Windows Powershell: notepad c:\Windows\System32\Drivers\etc\hosts
Ubuntu Terminal: sudo nano /etc/hosts
192.168.56.10 yourapp.local
Replace the DATABASES = ...
section in yourapp/settings.py
with the following:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'yourapp',
'USER': 'postgres',
'PASSWORD': 'admin',
'HOST': 'localhost',
'PORT': '',
}
}
Replace the ALLOWED_HOSTS = ...
in yourapp/settings.py
with the following:
ALLOWED_HOSTS = ['yourapp.local']
vagrant ssh -c 'cd /yourapp && python3 manage.py migrate'
vagrant ssh -c 'cd /yourapp && python3 manage.py createsuperuser'
vagrant ssh -c 'cd /yourapp && python3 manage.py runserver 0.0.0.0:8080'
Preview in browser:
http://yourapp.local:8080
These are not required as a part of the Vagrant deployment process - just a collection of helpful commands that might be required at some point in your Vagrant box.
vagrant ssh -c 'cd /yourapp && sudo -u postgres psql yourapp < yourapp.psql'
vagrant ssh -c 'cd /yourapp && sudo -u postgres pg_dump yourapp > yourapp.psql'
vagrant ssh -c 'cd /yourapp && sudo -u postgres dropdb yourapp && sudo -u postgres createdb yourapp'
vagrant ssh -c 'cd /yourapp && pip3 install --upgrade -r requirements.txt'
vagrant reload
vagrant destroy