This page goes through installing the necessary software applications for running GeoDjango.
Python
Python 2.5 is installed by default with Ubuntu 8.04. Ok, that was easy, lets move on to something else...
Apache HTTP Server
(Ref: http://articles.slicehost.com/2008/4/25/ubuntu-hardy-installing-apache-and-php5)
Install the Apache packages...
sudo aptitude install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert python-central libapache2-mod-python
Edit the Apache configuration file...
sudo nano /etc/apache2/apache2.conf
Add this line to the end of apache2.conf (replace 'myslice' with whatever you named your slice)
ServerName myslice
Restart Apache...
sudo apache2ctl graceful
sudo /etc/init.d/apache2 restart
The Apache Web server should have started. Verify this by browsing to http://11.222.333.444
You should see the following message...
It Works!
Subversion
Install the subversion application from the repository...
sudo apt-get install subversion
GeoDjango
Checkout the GeoDjango code...
svn co http://code.djangoproject.com/svn/django/branches/gis ~/django_gis
Setup a symbolic links so that Python knows how to find the GeoDjango code and the shell knows how to find the Django admin script.
sudo ln -s ~/django_gis/django /usr/lib/python2.5/site-packages/django
sudo ln -s ~/django_gis/django/bin/django-admin.py /usr/local/bin
Test that the Django Admin script can be found by entering the following...
django-admin.py help
... which should return a help message.
PostgreSQL
Install the PostgreSQL packages...
sudo aptitude install postgresql python-psycopg2 postgresql-server-dev-8.3 flex
Test to see that PostgreSQL is working...
sudo -u postgres psql postgres
Welcome to psql 8.3.1, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
postgres=# \q
Next we need to alter the default configuration to allow django to connect to the postgres server.
sudo nano /etc/postgresql/8.3/main/pg_hba.conf
Update the access records to the following...
# Database administrative login by UNIX sockets
local all postgres ident sameuser
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
#local all all ident sameuser
local all all password
# IPv4 local connections:
#host all all 127.0.0.1/32 md5
host all all 127.0.0.1 255.255.255.255 password
# IPv6 local connections:
#host all all ::1/128 md5
Restart the PostgreSQL server, so that it loads the new access configuration...
sudo /etc/init.d/postgresql-8.3 restart
GEOS, proj4, PostGIS, and GDAL
(Refs: http://trac.osgeo.org/geos/ and http://code.djangoproject.com/wiki/GeoDjangoInstall)
First, make a directory for downloading source code...
mkdir ~/downloads
The following commands download, build, and install the GEOS, proj4, PostGIS, and GDAL libraries. Run them all at once if you are feeling lucky, or one at a time if you want to watch the messages. Time to get a cup of coffee... this takes a while.
cd ~/downloads
wget http://geos.refractions.net/downloads/geos-3.0.0.tar.bz2
tar xjf geos-3.0.0.tar.bz2
cd geos-3.0.0
./configure
make
sudo make install
cd ~/downloads
wget ftp://ftp.remotesensing.org/proj/proj-4.6.0.tar.gz
wget ftp://ftp.remotesensing.org/proj/proj-datumgrid-1.3.tar.gz
tar xzf proj-4.6.0.tar.gz
cd ~/downloads/proj-4.6.0/nad
tar xzf ../../proj-datumgrid-1.3.tar.gz
cd ~/downloads/proj-4.6.0
./configure
make
sudo make install
cd ~/downloads
wget http://postgis.refractions.net/download/postgis-1.3.3.tar.gz
tar xzf postgis-1.3.3.tar.gz
cd postgis-1.3.3
./configure
make
sudo make install
cd ~/downloads
wget http://download.osgeo.org/gdal/gdal-1.5.1.tar.gz
tar xzf gdal-1.5.1.tar.gz
cd gdal-1.5.1
./configure --datadir=/usr/local/share
make
sudo make install
The GEOS library is now available in /usr/local/include/
The Proj4 files are now in /usr/local/bin/proj/
Update the shared library configuration file...
sudo nano /etc/ld.so.conf
and add the following line to the end
/usr/local/lib
Update the shared libraries...
sudo /sbin/ldconfig
Test that GDAL is installed correctly...
gdalinfo
Usage: gdalinfo [--help-general] [-mm] [-stats] [-nogcp] [-nomd]
[-noct] [-checksum] [-mdd domain]* datasetname
Test that Python, Django, GDAL, and GEOS are all working together
Start up Python...
python
Python 2.5.2 (r252:60911, Apr 21 2008, 11:17:30)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Check to see if Python can use the GDAL library...
>>> from django.contrib.gis.gdal import HAS_GDAL
>>> print HAS_GDAL
True
>>> from django.contrib.gis.tests import test_gdal
>>> test_gdal.run()
.......................
BEGIN - expecting IllegalArgumentException; safe to ignore.
ERROR 1: IllegalArgumentException: points must form a closed linestring
END - expecting IllegalArgumentException; safe to ignore.
......................
----------------------------------------------------------------------
Ran 45 tests in 0.094s
OK
Now check to see if Python can use the GEOS library...
>>> from django.contrib.gis.tests import test_geos
>>> test_geos.run()
Testing WKT output. ... ok
Testing HEX output. ... ok
Testing KML output. ... ok
Testing the Error handlers. ...
BEGIN - expecting GEOS_ERROR; safe to ignore.
GEOS_ERROR: ParseException: Expected number but encountered ','
GEOS_ERROR: ParseException: Unknown WKB type 255
END - expecting GEOS_ERROR; safe to ignore.
GEOS_ERROR: ParseException: Unexpected EOF parsing WKB
ok
Testing WKB output. ... ok
Testing creation from HEX. ... ok
Testing creation from WKB. ... ok
Testing EWKT. ... ok
Testing GeoJSON input/output (via GDAL). ... ok
Testing equivalence with WKT. ... ok
Testing Point objects. ... ok
Testing MultiPoint objects. ... ok
Testing LineString objects. ... ok
Testing MultiLineString objects. ... ok
Testing LinearRing objects. ... ok
Testing Polygon objects. ... ok
Testing MultiPolygon objects. ...
BEGIN - expecting GEOS_NOTICE; safe to ignore.
GEOS_NOTICE: Duplicate Rings at or near point 60 300
END - expecting GEOS_NOTICE; safe to ignore.
ok
Testing Geometry __del__() on rings and polygons. ... ok
Testing Coordinate Sequence objects. ... ok
Testing relate() and relate_pattern(). ... ok
Testing intersects() and intersection(). ... ok
Testing union(). ... ok
Testing difference(). ... ok
Testing sym_difference(). ... ok
Testing buffer(). ... ok
Testing the SRID property and keyword. ... ok
Testing the mutability of Polygons and Geometry Collections. ... ok
Testing three-dimensional geometries. ... ok
Testing the distance() function. ... ok
Testing the length property. ... ok
Testing empty geometries and collections. ... ok
Testing `ogr` and `srs` properties. ... ok
Testing use with the Python `copy` module. ... ok
Testing `transform` method. ... ok
Testing `extent` method. ... ok
Testing pickling and unpickling support. ... ok
----------------------------------------------------------------------
Ran 36 tests in 0.246s
OK
If the tests ran correctly, you now have GeoDjango installed. You can now proceed to
Part 4 - Creating a GeoDjango project.