PostGIS Basics – Part 1 – Installation

My OS is CentOS, so I used yum to handle installs from the rpm database. The thing with CentOS is that it is purposefully one step behind the cutting edge, so the most recent version of certain applications are not available (PHP, Postgres, etc). To get around this limitation, you have to instruct CentOS to look elsewhere for updated RPMs.

One location is the Postgresql repository:

Another location for these is DAG. To set this as an additional rpm source, run this command as root (this works for RHEL 5 and CentOS):

rpm -Uhv

Now we have the ability to get more up-to-date rpms.

Next, we must work on getting all of the dependencies for PostGIS installed, which amount to:


Unfortunately, rpms for the proj-4 application still weren’t available from the repository, so I found an rpm here: Proj-4 rpms. This installed with a quick rpm -U software-2.3.4.rpm


Geos is thankfully available from Dag, so yum should find it and install it. There may be some weird dependencies you will have to work through. The below packages should help, but they’ll all have to be installed eventually, so you may as well go ahead and do it.

  • php-pear
  • php-devel

* At this point, if you are using PDO and haven’t installed the pgsql PDO drivers, you can do it now: “pecl install pdo_pgsql”


You’ll need to run the following commands from a command line (either as root or the postgres user, I can’t recall which one is needed by which). Please note all of these paths seem to be unique to each installation, so yours might be different.

/usr/bin/initdb -D /var/lib/pgsql/data_dir    //Create the database

psql create language plpgsql  

psql -d database_name -f /usr/share/pgsql/contrib/lwpostgis.sql
psql -d database_name -f /usr/share/pgsql/contrib/spatial_ref_sys.sql

The last two lines load the spacial functions into the database for use.