Install PostgreSQL on FreeBSD 8.2 and make it work with Django
Follow up on my previous two blog posts:
- How to install and configure mod_wsgi on FreeBSD 8.2
- How to install and configure Django with mod_wsgi on FreeBSD 8.2
I am going to write down installation steps for PostgreSQL on FreeBSD 8.2 so it can be used with django.db.backends.postgresql_psycopg2 adapter.
#cd /usr/ports/databases/postgresql91-server #make #make install
Add this line to /etc/rc.conf:
postgresql_enable="YES"
Next, initialize a PostgreSQL database cluster:
#/usr/local/etc/rc.d/postgresql initdb
Now add this line to /usr/local/pgsql/data/postgresql.conf:
listen_addresses = '*'
Thirdly, add this line to /usr/local/pgsql/data/pg_hba.conf:
host all all 127.0.01/32 md5
Reboot. Now let’s create a new user for our PostgreSQL database:
#su pgsql $ createuser -sdrP username Enter password for new role: ****** Enter it again: ****** $ exit
Finally, we need to install psycopg2 client in order to be able to connect to the PostgreSQL server from a Django web application.
#pip install psycopg2 #/usr/local/sbin/apachectl restart
Cool. Now you should be able to connect to the PostgreSQL server from your Django app. Make sure to create a database first:
#su pgsql $ createdb myapp $ exit
Now go to your Django application folder and edit settings.py. Use django.db.backends.postgresql_psycopg2 as ENGINE, also set NAME, USER and PASSWORD fields. Reload the Django app in the browser and it should work fine.
Another very useful tutorial, thanks Richard!
Note typo in IP address: 127.0.01/32
See the FreeBSD Wiki (http://wiki.freebsd.org/Jails) for information on making PostgreSQL work in a Jail
Bill