Skip to content
derekeder edited this page Oct 31, 2012 · 18 revisions

These instructions are based on http://imperialwicket.com/aws-configuring-a-geo-spatial-stack-in-amazon-linux (though we came across some issues along the way, documented here)

# install postgresql
sudo yum install postgresql postgresql-server postgresql-devel
sudo mkdir /usr/local/pgsql/
sudo mkdir /usr/local/pgsql/data
sudo chown postgres /usr/local/pgsql/data
sudo su postgres
initdb -D /usr/local/pgsql/data
postgres -D /usr/local/pgsql/data &
exit

Install PostGIS. This requires some build tools, and also the GEOS and PROJ libraries. On a Micro instance, making the GEOS and PROJ libraries will take a while (about 5-10 minutes), and drive your server load average to the 1.00-2.00 range. I'm going to unnecessarily change directories to what should be the current working directory a few times, just to make sure we're in the same place. After GEOS, PROJ, and PostGIS are built, we will also need to update our libraries, so the server knows where to find them.

sudo yum install gcc make gcc-c++ libtool libxml2-devel
# make a directory for building
cd /home/ec2-user/
mkdir postgis
cd postgis

# 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
cd /home/ec2-user/postgis/
wget http://download.osgeo.org/proj/proj-4.7.0.tar.gz
wget http://download.osgeo.org/proj/proj-datumgrid-1.5.zip
tar xzf proj-4.7.0.tar.gz
cd proj-4.7.0/nad
unzip ../../proj-datumgrid-1.5.zip
cd ..
./configure  
make
sudo make install

# download, configure, make, install postgis
cd /home/ec2-user/postgis/
wget http://postgis.refractions.net/download/postgis-1.5.6.tar.gz
tar xzf postgis-1.5.6.tar.gz 
cd postgis-1.5.6
./configure --with-geosconfig=/usr/local/bin/geos-config
make
sudo make install

# update your libraries
sudo su
echo /usr/local/lib >> /etc/ld.so.conf
exit
sudo ldconfig

Now that PostGIS is installed, we should create a template database for PostGIS. Anytime you are generating a new database that requires geospatial data, you can create it from this template.

The default sql scripts for setting up postGIS have some errors in them in postgis-1.5.2. See http://trac.osgeo.org/postgis/ticket/1820 and http://trac.osgeo.org/postgis/changeset/9735. The fix is to do a global replace in both sql files to replace 'C' with 'c' and 'SQL' with 'sql'.

# setup our postgis template
createdb -U postgres template_postgis
createlang -U postgres plpgsql template_postgis
psql -U postgres -d template_postgis -f /usr/share/pgsql/contrib/postgis-1.5/postgis.sql
psql -U postgres -d template_postgis -f /usr/share/pgsql/contrib/postgis-1.5/spatial_ref_sys.sql

Currently configuring apache and python: http://agiliq.com/blog/2009/03/django-with-mysql-and-apache-on-ec2/

Clone this wiki locally