Compiling PostGIS 1.5 and installing after Yum PostgreSQL Install
UPDATE: Since this article was written, Yum now comes packaged with PostGIS 1.5. Please refer to PostGIS Yum Install for PostgreSQL 9.0 if you want to go with a faster more idiot proof install process

A couple of people have asked this, so thought we would address the common issues people run into with compiling PostGIS.

The first question, some will ask is Why don't you just take the packaged PostGIS that comes with the PostgreSQL Yum repository?

There are two reasons for not installing PostGIS under using Yum and our general reasons for not.

NOTE: PostGIS 1.3, PostGIS 1.4, PostGIS 1.5 can coexist on the same PostgreSQL daemon service as long as they are installed in different databases. They will all share the same Proj and GEOS. So installing PostGIS 1.5 will not break your PostGIS 1.4 or 1.3 installs. The newer GEOS 3.2.0 C-API is backward compatible with older GEOS C-API and the C-API is what PostGIS uses.

Now that we answered the why, the next is How?. For this How section, we'll outline the things you need to compile first which are NOT packaged with PostGIS. We will also be focusing on the upcoming PostGIS 1.5. We will also outline the common issues people run into. Issues are most common on a 64-bit Linux Centos/Redhat EL.

Basic overview steps

  1. Install PostgreSQL using Yum as we outlined in PostgreSQL 8.4 Yum Install. Also remember to yum install postgresql-dev. Do not yum install postgis.
  2. download, compile, install proj 4.6+, don't forget nad datum shift folder
  3. download, compile, install geos 3.2 from http://trac.osgeo.org/geos/ . Note seem to run into fewer linking issues if you download from SVN, but then you have to do a yum install svn to install subversion client.
  4. download, compile, install libxml 2.6+ - ftp://xmlsoft.org/libxml2/libxml2-2.7.6.tar.gz (this is a new dependency for PostGIS 1.5 to support the ST_GeomFromGML and ST_GeomFromKML functions). It is not required for older versions of PostGIS.
  5. download, compile, install postgis http://www.postgis.org/downloads
  6. Fix geos / proj linking errors if you run into them. This seems to be more of an issue with 64-bit Linux than any other we have run into. We'll go over how to discover missing links and fix them.

Preprep

Yum Installs you need. As mentioned you need to Yum install PostgreSQL and postgresql-devel.

Missing G++, GCC

If you run into issues like complaints about no gcc+ compiler, then you probably need to:

yum install gcc-c++

mkdir /sources
cd /sources

Download and install Proj


cd /sources
mkdir proj
cd proj
wget http://download.osgeo.org/proj/proj-4.6.1.tar.gz
tar -xvf proj-4.6.1.tar.gz
wget http://download.osgeo.org/proj/proj-datumgrid-1.4.zip
unzip proj-datumgrid-1.4.zip  -d  proj-4.6.1/nad
cd proj-4.6.1
./configure
make
make install
ldconfig

Download and install GEOS


cd /sources
mkdir geos
cd geos
wget http://download.osgeo.org/geos/geos-3.2.0.tar.bz2
tar -xvf geos-3.2.0.tar.bz2
cd geos-3.2.0
./configure
make & make install
make check
ldconfig

Download and install libxml

This is only needed for PostGIS 1.5+

	
cd /sources
mkdir libxml
cd libxml
wget ftp://xmlsoft.org/libxml2/libxml2-2.7.6.tar.gz
tar -xvf libxml2-2.7.6.tar.gz
cd libxml2-2.7.6
./configure
make & make install
ldconfig
	

Download and install PostGIS 1.5 SVN

You may swap this out with PostGIS 1.4.1 for mission critical production use, but we are demonstrating PostGIS 1.5 SVN. This is going to be a really exciting release once we get all our ducks in a row hopefully by early to Mid January 2010.


cd /sources
mkdir postgis
cd postgis
wget http://www.postgis.org/download/postgis-1.5.0SVN.tar.gz
tar -xvf postgis-1.5.0SVN.tar.gz
cd postgis-1.5.0SVN
./configure
make
make install
make check
ldconfig

Problems

Its very common to run into linking issues particularly with GEOS or Proj on a 64-bit that its either pointing at an old version or non-existent location. To detect said linking issues do the following:


ldd -d /usr/lib64/pgsql/postgis-1.5.so (to show all the dependencies (or ldd -d /usr/lib/pgsql/postgis-1.5.so  if you are on 32-bit)
ldd -d /usr/lib64/pgsql/postgis-1.5.so | grep libgeos   (or ldd -d /usr/lib/pgsql/postgis-1.5.so  if you are on 32-bit)
ldd -d /usr/lib64/pgsql/postgis-1.5.so | grep libproj   (or ldd -d /usr/lib/pgsql/postgis-1.5.so  if you are on 32-bit)

You should get something of the form below which would tell me my geos is pointing at an older version

libgeos_c.so.1 => /usr/lib64/libgeos_c.so.1 
libgeos-3.1.0.so => /usr/local/lib/libgeos-3.1.0.so (0x00110000)

To fix, may not be the best of solutions, but I destroy the symlinks and relink them something of the form:


rm /usr/lib/libgeos_c.so.1
ln -s /usr/local/lib/libgeos_c.so.1.6.0 /usr/lib64/libgeos_c.so.1
ln -s /usr/local/lib/libproj.so /usr/lib64/libproj.so.0 

Installing PostGIS in a db

The insall path will be changing shortly -- but you can always find the sql files in the source folder: Here we are creating a template_postgis15.

createdb template_postgis15 -U postgres
cd /sources/postgis/postgis-1.5.0SVN
psql -d template_postgis15 -U postgres -c "CREATE LANGUAGE plpgsql"
psql -d template_postgis15 -U postgres -f postgis/postgis.sql
psql -d template_postgis15 -U postgres -f spatial_ref_sys.sql
#this installs the help description for each function you can search via psql or pgadmin
psql -d template_postgis15 -U postgres -f doc/postgis_comments.sql
	

To verify all is good, run the below command in the database you just created using psql or PgAdminIII

SELECT postgis_full_version();

You should get an output something like:

POSTGIS="1.5.0SVN" GEOS="3.2.0-CAPI-1.6.0" PROJ="Rel. 4.6.1, 21 August 2008" LIBXML="2.7.6" USE_STATS