[[TOC()]] '''Warning:''' This is ''not'' the official !GeoDjango installation instructions for Ubuntu -- it is a reference wiki combed from user-contributed material. Thus, the material therein may be outdated and/or incorrect. Please consult the [http://geodjango.org/docs/install.html#ubuntu official Ubuntu installation documentation at geodjango.org] before attempting to use the instructions here. = !GeoDjango Dependencies with Apt-get on Ubuntu = The GeoDjangoInstall wiki describes in detail how to install GeoDjango dependencies from '''source''', which for many reasons is a great approach. However, with Ubuntu releases you can also use the '''Synaptic Package Manager''' (`apt-get install` on the command line) to handle some of the installation work for you. In the next version of Ubuntu (8.10), it will likely be possible to install almost everything needed using Synaptic as libraries are updated. * Note: if you take this route, be advised that the location of install directories will differ significantly from the source install approach. ie. PostGIS will be installed inside the PostgreSQL contrib and share directories specific to the PostgreSQL version number. This writeup is based on Ubuntu 8.04 LTS. Any readers should update this document based on their experience from this version and note differences with newer versions. == Short Version == The following is a list of commands to enter into the Terminal to install GeoDjango on Ubuntu. For more detailed explanations on the installation process see the GeoDjangoInstall wiki. {{{ #Download and Install the latest version of Django cd ~ wget http://www.djangoproject.com/download/1.0/tarball/ tar xzvf Django-1.0.tar.gz sudo python ~/Django-1.0/setup.py install #Enter password to give root privileges as prompted throughout the installation #Install Apache2, PsycoPg2, PostGreSQL, PostGIS, build-essential [to be able to compile libraries], and Mod_Python sudo apt-get install apache2 python-psycopg2 postgresql build-essential libapache2-mod-python postgresql-8.3-postgis #Press 'y' to confirm download wget http://download.osgeo.org/geos/geos-3.0.0.tar.bz2 # The version in the Repositories is currently not new enough for GeoDjango wget http://download.osgeo.org/gdal/gdal-1.5.2.tar.gz # The version in the Repositories is currently not new enough for GeoDjango wget http://download.osgeo.org/proj/proj-4.6.1.tar.gz # The version in the Repositories likely will not properly build the proj datum shifting files tar xjf geos-3.0.0.tar.bz2 cd geos-3.0.0 ./configure make sudo make install cd .. tar xzf proj-4.6.1.tar.gz wget ftp://ftp.remotesensing.org/proj/proj-datumgrid-1.4.tar.gz cd proj-4.6.1/nad tar xzf ../../proj-datumgrid-1.4.tar.gz cd .. ./configure make sudo make install cd .. tar xzf gdal-1.5.2.tar.gz cd gdal-1.5.2 ./configure make sudo make install cd .. sudo pico /etc/postgresql/8.3/main/pg_hba.conf #Edit to allow Django Connections, as per the regular Django Docs sudo pico /etc/apache2/sites-available/default #Edit to Create Django Locations, as per the regular Django Docs }}} Create your PostGIS enabled PostgreSQL db {{{ sudo su postgres createuser [username] psql alter user [username] with password '[password]'; \q createdb [dbname] createlang plpgsql [dbname] psql -d [dbname] -f /usr/share/postgresql-8.3-postgis/lwpostgis.sql psql -d [dbname] -f /usr/share/postgresql-8.3-postgis/spatial_ref_sys.sql }}} Notes {{{ Add the following to near the beginning of the settings.py file for any GeoDjango app you create: GDAL_LIBRARY_PATH = '/usr/local/lib/libgdal.so' Add the following to the Apache2 config file in the Location Subsection: SetEnv GDAL_DATA /usr/local/share/ }}} == Full Instructions == === Step 1 === Download all needed programs and libraries using apt-get and wget [commandline] or Synaptic and Firefox [GUI]: {{{ apt-get install apache2 python-psycopg2 postgresql build-essential libapache2-mod-python postgresql-8.3-postgis wget http://www.djangoproject.com/download/1.0/tarball/ wget http://download.osgeo.org/gdal/gdal-1.5.2.tar.gz wget http://download.osgeo.org/geos/geos-3.0.0.tar.bz2 wget http://download.osgeo.org/proj/proj-4.6.1.tar.gz wget http://download.osgeo.org/proj/proj-datumgrid-1.4.tar.gz }}} Synaptic or apt-get will download and install the specified packages in one step. Django and the other libraries still need to be installed as described below. === Step 2 === * Open up access in the pg_hba.conf file {{{ sudo pico /etc/postgresql/8.3/main/pg_hba.conf #Alternatively use gedit or a text editor of your choice # change ident sameuser to trust - WARNING SECURITY RISK # comment out this line to allow, for instance, to django/psycopg2 to connect without password local all postgres ident sameuser }}} * Restart (or start) the server by switching into the default postgres user {{{ sudo su - postgres /etc/init.d/postgresql-8.3 start exit }}} === Step 3 === Compile and install these libraries so GeoDjango can find them. Install Proj4 exactly like the full instructions here: http://code.djangoproject.com/wiki/GeoDjangoInstall#PROJ.4 Extract gdal-1.5.2.tar.gz and geos-3.0.0 to folders on your Desktop and install: {{{ #in the geos-3.0.0 directory ./configure make sudo make install #in the proj-4.6.1 directory cd proj-4.6.1/nad tar xzf ../../proj-datumgrid-1.4.tar.gz cd .. ./configure make sudo make install #in the gdal-1.5.2 directory ./configure make sudo make install sudo cp ~/Desktop/geos-3.0.0/capi/libs/* /usr/lib/ sudo cp /usr/share/gdal/gcs.csv /usr/local/share/ }}} === Step 4 === Create your PostGIS `template_postgis` database {{{ # Switch to the default postgres user sudo su - postgres # Create a template database with UTF encoding owned by the postgres user (or your user of choice) createdb -E UTF8 -O postgres -U postgres template_postgis # Now you can switch back to your normal user exit # Load the required procedural language for postgis createlang plpgsql -d template_postgis -U postgres }}} Now you are ready to actually load the postgis functions and tables as sql inserts * Note: the two postgis sql files (lwpostgis.sql and spatial_ref_sys.sql) were likely installed in the postgres share directory {{{ pg_config --sharedir # will give you that dir # Also look in: ls /usr/share/ # or /usr/local/share/ }}} Try: {{{ psql -d template_postgis -U postgres -f /usr/share/postgresql-8.3-postgis/lwpostgis.sql # Note: ignore any NOTICES, like 'psql:/usr/share/lwpostgis.sql:44: NOTICE: type "histogram2d" is not yet defined' }}} * You should see output like: {{{ BEGIN CREATE FUNCTION CREATE OPERATOR [...] CREATE TYPE CREATE AGGREGATE COMMIT }}} * If you get an error about not being able to find `geos` add /usr/local/lib to /etc/ld.so.conf and run: {{{ ldconfig # Then restart PostgreSQL }}} Then load the geographic projections table: {{{ psql -d template_postgis -U postgres -f /usr/share/postgresql-8.3-postgis/spatial_ref_sys.sql }}} Whoa! Hopefully that worked, and you will only have to do it once! From then on create a PostGIS database like: {{{ createdb -U postgres -T template_postgis DB_NAME }}} === Step 5 === Return to GeoDjangoInstall for troubleshooting and tests for GDAL and GEOS (see bottom of page) === Step 6 === Check out [http://mapserver.gis.umn.edu/ MapServer], [http://mapnik.org/ Mapnik], and [http://openlayers.org/ OpenLayers], open source mapping applications recommended for use with !GeoDjango. Install these using Synaptic or the command: {{{ sudo apt-get install cgi-mapserver python-gdal python-mapscript }}}