Installing and Configuring PostgreSQL and PostGIS on Amazon Linux
A step by step tutorial on installing and configuring PostgreSQL and PostGIS on an Amazon EC2 instance running Amazon Linux AMI. The procedure has been tested on Amazon Linux AMI, but should also apply in general to Fedora/Red Hat/CentOS distributions.
1. Install Linux updates, set time zones, followed by GCC and Make
sudo yum -y updatesudo ln -sf /usr/share/zoneinfo/America/Indianapolis \ /etc/localtimesudo yum install -y gcc make gcc-c++
2. Install Readline and zlib libraries
sudo yum -y install readline-develsudo yum -y install zlib-devel
3. Download and Install PostgreSQL database server
wget http://ftp.postgresql.org/pub/source/v9.2.2/postgresql-9.2.2.tar.bz2bzip2 -d postgresql-9.2.2.tar.bz2tar -xf postgresql-9.2.2.tarcd postgresql-9.2.2
./configuregmakesudo gmake install
4. Configure PostgreSQL database server
sudo adduser postgressudo passwd postgres<Enter Password>
sudo mkdir /usr/local/pgsql/datasudo chown postgres /usr/local/pgsql/datasu - postgres/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &/usr/local/pgsql/bin/createdb test/usr/local/pgsql/bin/psql testexit
If you get a 'There are stopped jobs' message:
cd /home/ec2-user/postgresql-9.2.2/contrib/fuzzystrmatchmakesudo make install
su - postgresPassword:<type your password set in 4 above>/usr/local/pgsql/bin/psqlpsql (9.2.2)postgres=#
7. Make a directory for PostGIS
cd /home/ec2-user/mkdir postgis cd postgis
8. Download and Install requirements for PostGIS Installation
a. Get Proj4 reprojection library (version 4.6.0 or greater)
wget http://download.osgeo.org/proj/proj-4.8.0.tar.gzgzip -d proj-4.8.0.tar.gztar -xvf proj-4.8.0.tarcd proj-4.8.0./configuremakesudo make install
b. GEOS geometry library (version 3.2.2 or greater)
cd /home/ec2-user/postgiswget http://download.osgeo.org/geos/geos-3.3.7.tar.bz2bzip2 -d geos-3.3.7.tar.bz2tar -xvf geos-3.3.7.tarcd geos-3.3.7 ./configure make sudo make install
c. LibXML2, (version 2.5.x or higher)
sudo yum -y install libxml2-devel
d. JSON-C, (version 0.9 or higher)
cd /home/ec2-user/postgiswget http://oss.metaparadigm.com/json-c/json-c-0.9.tar.gzgzip -d json-c-0.9.tar.gztar -xvf json-c-0.9.tarcd json-c-0.9./configuremakesudo make install
e. GDAL, (version 1.6 or higher)
cd /home/ec2-user/postgiswget http://download.osgeo.org/gdal/gdal-1.9.2.tar.gzgzip -d gdal-1.9.2.tar.gztar -xvf gdal-1.9.2.tarcd gdal-1.9.2./configuremakesudo make install
sudo suecho /usr/local/lib >> /etc/ld.so.confexit
cd /home/ec2-user/postgiswget http://postgis.net/stuff/postgis-2.0.3SVN.tar.gzgzip -d postgis-2.0.3SVN.tar.gztar -xf postgis-2.0.3SVN.tarcd postgis-2.0.3SVN./configure --with-pgconfig=/usr/local/pgsql/bin/pg_config --with-rastermakesudo make install
11. Build PostGIS Extensions and Deploy
cd extensions/postgismake cleanmakesudo make installcd ..cd postgis_topologymake cleanmakesudo make install
If this tutorial was helpful to you, then please do not forget to leave a comment, or two. :)