Read and used this article about creating a geospatial stack on Amazon EC2 Linux; it was written for 8.4 and pretty much everything is the same, here's the updated commands for Postgres 9.x. I just go sudo -i when executing the following commands. These are long compilation processes on an m1.small so as always screen (or tmux) is your friend.
sudo -i # or just prefix necessary installs with sudo
yum update
yum install postgresql-libs postgresql postgresql-server postgresql-develYou'll have to finish through setting up and getting the Postgres server running since it'll likely be different - in my case I put my pgdata directory on an EBS volume. Depending on the state of your instance you may need to install the following (and it doesn't hurt to try to install what you've already installed) :
sudo yum install gcc make gcc-c++ libtool libxml2-develTo install PostGIS you'll need to install the following software:
geos-3.3.5 proj-4.8.0 gdal-1.9.1 postgis-2.0.1I expanded all my source in /usr/local/src but I really don't know how these things are supposed to go, just seems like a good place to put it. The following commands are essentially stolen from the original article with version numbers updated (if you have newer versions I imagine you could slot those in as well).
# hmm maybe cd /usr/local/src # download, configure, make, install geos wget http://download.osgeo.org/geos/geos-3.3.5.tar.bz2 tar xjf geos-3.3.5.tar.bz2 cd geos-3.3.5 ./configure make sudo make install # download, configure, make, install proj # this one is a little tricky, pay attention wget http://download.osgeo.org/proj/proj-4.8.0.tar.gz wget http://download.osgeo.org/proj/proj-datumgrid-1.5.zip tar xzf proj-4.8.0.tar.gz cd proj-4.8.0/nad unzip ../../proj-datumgrid-1.5.zip cd .. ./configure make sudo make install # gdal, you may need to install svn (yum install svn) svn checkout https://svn.osgeo.org/gdal/trunk/gdal gdal cd gdal ./configure --with-python make sudo make install # download, configure, make, install postgis wget http://postgis.refractions.net/download/postgis-2.0.1.tar.gz tar xzf postgis-2.0.1.tar.gz cd postgis-2.0.1 ./configure --with-geosconfig=/usr/local/bin/geos-config make sudo make install # update your libraries sudo -i echo /usr/local/lib > /etc/ld.so.conf.d/postgis.conf # assumes your /etc/ld.so.conf loads all /etc/ld.so.conf.d/*.conf ldconfig exit
Fire up psql and verify:
SELECT name, default_version,installed_version FROM pg_available_extensions;
You should see both postgis and postgis_topology. If postgis is not present then you're likely missing one of the prerequisites - I was setting this up a second time following my own instructions and found I had omitted GDAL (which I have now included in these directions).
To enable PostGIS in the current database:
CREATE EXTENSION postgis;