Main.InstallingAPostGIS-enabledApacheServer


Minimal instructions for a step-by-step installation of a full PostGIS-enabled web stack:

Has everyone noticed that all the letters of the word database" are typed with the left hand? Now the layout of the QWERTYUIOP typewriter keyboard was designed, among other things, to facilitate the even use of both hands. It follows, therefore, that writing about databases is not only unnatural, but a lot harder than it appears. -- fortune cookie

This tutorial is geared towards from-source compilation of all the pieces on a linux system (such as Slackware) with little regard to integration with dependency-tracking package managers, and might cause conflicts with your system-installed components if your linux distribution makes use of such systems (apt or yum for example). This is mitigated somewhat by the fact that the standard location for "extra-system" insteallations is used: /usr/local/

This document presumes one primarily works as a non-root user in a certain home directory prepared for the work. Middleware components are downloaded to /home/USER/Setup/Middleware/

Install zlib 1.2.5

NOTE: This step is for when development files (includes etc) are not already available on your system, and you are confidant about installing a replacement zlib library without causing problems with other packages.

IMPORTANT This particular package can be easily skipped (and is maybe best left out) since GDAL comes with it's own inbuilt copy of zlib, and most linux systems ship with an already-up-to-date version. Nonetheless, you may still not have the requisite developer files needed to complete later parts of this tutorial, for example on Red Hat 5, I skipped this step but still needed to install zlib-devel via yum install -y zlib-devel as root.

  1. 532K, MD5 checksum c735eab2d659a96e5a594c9e8541ad63
  2. As a NON-ROOT user in ~/Setup/Middleware/
  3. Check the package for tampering/corruption:
    1. openssl dgst zlib-1.2.5.tar.gz
    2. results should map the checksum above
  4. tar -xvf zlib-1.2.5.tar.gz
  5. cd zlib-1.2.5
  6. ./configure
  7. make
  8. su root
  9. <Enter root password>
  10. make install
  11. ldconfig (as root)
  12. exit (revert to non-root user)

Install proj 4.7.0

Proj.4 is a software package providing all sorts of geographic projection and coordinate system management. Software we will install later, such as GDAL? for example, make use of this library.

By default the proj.4 compilation process builds both shared and static libraries.

  1. As a NON-ROOT user in ~/Setup/Middleware/
  2. tar -xvf proj-4.7.0.tar.gz
  3. cd proj-4.7.0
  4. ./configure
  5. make
  6. su root
  7. <Enter root password>
  8. make install
  9. ldconfig
  10. exit (revert to non-root user)

When using the default configuration (as above) Proj.4 adds the following files into /usr/local/include:

  • nad_list.h
  • org_proj4_Projections.h
  • proj_api.h
  • projects.h

..and the following files into /usr/local/lib/

  • libproj.a
  • libproj.la
  • libproj.so
  • libproj.so.0
  • libproj.so.0.6.6

...and the following binaries (programs) into /usr/local/bin:

  • geod
  • invproj
  • nad2nad

Install GEOS 3.3.5

Project Website: http://trac.osgeo.org/geos

NOTE:

With GEOS 3.2.2, I (presuming GEOS would spew out a clutter of files into the /usr/local/include directory) originally tried to specify a clean sub-directory for files to go into by using ./configure --includedir=/usr/local/include/geos and this worked - except then geos-config does not return correct results, causing problems for later dependent builds. Anyway, GEOS turned out to be clean enough anyway - it already makes an include/geos/ directory which mirrors the source file layout.

GEOS does not (that I can find) offer file hashes for comparison with downloaded copies. My copy looked like this:

MD5(geos-3.3.5.tar.bz2)= 2ba61afb7fe2c5ddf642d82d7b16e75b

The GEOS compilation process build both shared and static libraries by default.

  1. As a NON-ROOT user in ~/Setup/Middleware/
  2. tar -xvf geos-3.3.5.tar.bz (if "tar" does not work - will require bzip)
  3. cd geos-3.3.5
  4. ./configure
  5. make
  6. su root
  7. <Enter root password>
  8. make install
  9. ldconfig
  10. exit (revert to non-root user)

The standard GEOS installation places the following into /usr/local/include/

  • geos/ (a folder of API includes)
  • geos_c.h
  • geos.h

...and the following files into /usr/local/lib/

  • geos/ (an empty folder, I presume for swig wrappers etc)
  • libgeos.a
  • libgeos_c.la
  • libgeos_c.so.1
  • libgeos.la

...and the following binaries into /usr/local/bin/:

  • geos-config

Installing PostgreSQL 9.2

Project website: http://www.postgresql.org Source code: http://www.postgresql.org/ftp/source/v9.2.0/

On Red-hat based systems you may need to install openssl-devel and zlib-devel packages in order to complete this compilation. In this case, the configure stage will fail with notices to this effect.

  1. MD5 (postgresql-9.2.0.tar.bz2) = 8c4c32a4abe8cf61b02c8366181ede50
  2. As a NON-ROOT user in ~/Setup/Middleware/
  3. openssl dgst postgresql-9.2.0.tar.bz2
  4. tar -xvf postgresql-9.2.0.tar.bz2
  5. cd postgresql-9.2.0
  6. LDFLAGS=-lstdc++ ./configure --with-libedit-preferred --with-perl --with-openssl --with-includes=/usr/local/include --with-libs=/usr/local/lib
    1. NOTE: The LDFLAGS override is to allow later linking of C++ bits (GEOS/PostGIS) with the core database
    2. NOTE: the --with-perl is not really needed for now, and the --with-includes and --with-libs are not really needed either.
  7. make
  8. su root
  9. <Enter root password>
  10. make install
  11. ldconfig
  12. exit (revert to non-root user)

Set up PostgreSQL users and initialize a database cluster

  1. As a NON-ROOT user in ~/Setup/Middleware/
  2. su root
  3. <Enter root password>
  4. /usr/sbin/adduser postgres
    1. Record postgres password
  5. mkdir /usr/local/pgsql/data
  6. chown postgres /usr/local/pgsql/data
  7. su postgres
  8. <Enter postgres password>
  9. /usr/local/pgsql/bin/initdb --locale=POSIX --encoding=UTF8 -D /usr/local/pgsql/data
    1. Upon success you will receive the following output:
      ...
      ...
      WARNING: enabling "trust" authentication for local connections
      You can change this by editing pg_hba.conf or using the option -A, or
      --auth-local and --auth-host, the next time you run initdb.
      
      Success. You can now start the database server using:
      
          /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
      or
          /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
  10. exit (revert to non-postgres user)
  11. exit (if root, revert to non-root user)

Start the Postgres server and initialize a test database:

  1. As a NON-ROOT user in ~/Setup/Middleware/
  2. su postgres
  3. <Enter postgres password>
  4. /usr/local/pgsql/bin/pg_ctl -l /usr/local/pgsql/data/logfile -D /usr/local/pgsql/data start
  5. ps -A (check for running postgres daemons)
  6. /usr/local/pgsql/bin/createdb test
  7. /usr/local/pgsql/bin/psql test (will log into "test" database with "psql" client program)
  8. Should see a psql query prompt (something like "test=#")
  9. \q (to exit psql client program)
  10. Stop the server until later:
  11. /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data stop
  12. exit (to log off postgres user)

TODO: Document service start/stop scripts (/etc/rc.d/ scripts on Slackware


Installing PostGIS 2.0.1

Project website: http://postgis.refractions.net/

Latest stable version: http://postgis.refractions.net/download/postgis-2.0.1.tar.gz

On a Redhat-based machine I needed to install the libxml2-devel package in order to proceed with this compilation (the configure step failed to find the pre-requisites).

I also had trouble (On Red-hat) with the postgis library failing to load it's GEOS prerequisite, and needed to add /usr/local/lib to /etc/ld.so.conf.d/

UTF-8 issues with older versions (1.5.3 and .5): http://postgresql.1045698.n5.nabble.com/many-tables-vs-large-tables-td2090518.html

  1. Reminder PostGIS 1.5 can only use int4 as index columns for spatial tables (TODO: check this in newer versions)
  2. As a NON-ROOT user in ~/Setup/Middleware/
  3. tar -xvf postgis-2.0.1.tar.gz
  4. cd postgis-2.0.1
    1. PostGIS 1.5.1+ seems not to need --with-geos or --with-proj. They are found automatically by configure. Instead use:
    2. ./configure --with-pgconfig=/usr/local/pgsql/bin/pg_config --without-raster
  5. make
  6. su root
  7. <Enter root password>
  8. make install
  9. exit (revert to non-root user)
  10. su postgres
  11. <Enter postgres password>
  12. Setting up spatial DBs - make sure the postgres server is running as above
  13. /usr/local/pgsql/bin/psql -d test -f /usr/local/pgsql/share/contrib/postgis-2.0/postgis.sql 2> temp_log.txt
    1. Should see multiple CREATE lines and a final COMMIT, followed by a few cleanup DROPs
  14. /usr/local/pgsql/bin/psql -d test -f /usr/local/pgsql/share/contrib/postgis-2.0/spatial_ref_sys.sql
    1. Should see multiple INSERT lines and a final COMMIT and VACUUM
  15. exit (to log off postgres user)

Useful Links