WebFaction
Community site: login faq
0
4

I know there is a private PostgreSQL instance install guide, but I need to install the a local PostgreSQL instance with the PostGIS extensions. How?

Note: If you only need PostgreSQL plus PostGIS for your project, then you do not need to follow this guide. PostgreSQL is already available on our servers, and PostGIS can be installed by the WebFaction Support team on your databases for you - just add the PostGIS extenstion to your database via the Control Panel at https://my.webfaction.com/databases

This guide is only needed when you need a private PostgreSQL instance, and also want the PostGIS extensions installed locally on that private instance. This is usually done because you need a newer PostGIS version, or because you also want to then install additional geospatial libraries (like the latest version of proj4) thereafter, in addition to PostGIS.

asked 16 Aug '12, 00:06

ryans ♦♦
5.0k93460
accept rate: 43%

edited 19 Mar '15, 06:31

Hi, I do need proj4 in order to install GeoDjango. Is it possible to use Webfaction provided PostgreSQL + PostGIS and have my own proj4 installation,say, on $HOME/lib ? I really prefer to use yours managed server instead of mine :-)

Or is there other way to have GeoDjango installed?

Thanks,

Mário

(30 Aug '12, 11:50) Mario

PROJ is already installed on our servers, here are the current specs for the CentOS 6 machine using SELECT PostGIS_full_version();

POSTGIS="1.5.3" GEOS="3.3.5-CAPI-1.7.5" PROJ="Rel. 4.7.1, 23 September 2009" LIBXML="2.7.6" USE_STATS

If you need a different version of PROJ, you will need to install your own version PostgreSQL and PostGIS.

(30 Aug '12, 12:22) timg ♦♦

wow! I think this is enough! I'll open a ticket to get a postgis enabled database and start the tests.

Thanks Mário

(30 Aug '12, 12:41) Mario

Please note that now it is even easier: from your panel/dashboard you can just install the postgis extension while creating the database, and I think it is editable afterwards too.

(12 May '14, 12:08) nathanvda

Here is an installation guide for PostgreSQL with the PostGIS extensions.

The first thing you're going to need in order to compile this is GCC 4.6. Please start by following this GCC 4.6 install guide before proceeding further. The rest of this guide assumes that you will perform all compilation with the newer version of GCC.

Like the related PostgreSQL Install Guide, you still need to create a new Custom Application (listening on port) in the control panel called "pgport" to reserve a port. Be sure to enter it in the script below in a line that looks like this:

PGPORT=77777

You can run these commands individually, or you can paste them into a shell script and run it as

bash build_psql.sh | tee build_psql.log

Either way, you may want to run it in a screen session.

#!/bin/bash

mkdir -p $HOME/bin $HOME/lib $HOME/src $HOME/tmp

# Be sure to set this port to one assigned to a Custom Application (listening on port)
PGPORT=77777
PYTHON=python2.7

export TMPDIR=$HOME/tmp
export PATH="$HOME/bin:$PATH"
export C_INCLUDE_PATH="$HOME/include:$C_INCLUDE_PATH"
export LIBRARY_PATH="$HOME/lib:$LIBRARY_PATH"
export LD_LIBRARY_PATH="$HOME/lib:$LD_LIBRARY_PATH"

############################################################
# CARTODB COMPLETE INSTALL - DEPENDENCIES & INSTALL PRIORITY
############################################################
# PROGRAM:          VERSION:    NOTES:
# ----------------------------------------------------------
# GDAL              (1.9.2)     http://download.osgeo.org/gdal/gdal-1.9.2.tar.gz
# GEOS              (3.4.2)     http://download.osgeo.org/geos/geos-3.4.2.tar.bz2
# Postgres          (9.1.15)    https://ftp.postgresql.org/pub/source/v9.1.15/postgresql-9.1.15.tar.bz2
# PostGIS           (2.1.5)     http://download.osgeo.org/postgis/source/postgis-2.1.5.tar.gz

############################################################
# GDAL (1.9.2)
# http://download.osgeo.org/gdal/gdal-1.9.2.tar.gz
############################################################
cd ~/src
wget http://download.osgeo.org/gdal/gdal-1.9.2.tar.gz
tar -xzf gdal-1.9.2.tar.gz
cd gdal-1.9.2
./configure --prefix=$HOME
make
make install

############################################################
# GEOS (3.4.2)
# http://download.osgeo.org/geos/geos-3.4.2.tar.bz2
############################################################
cd ~/src
wget http://download.osgeo.org/geos/geos-3.4.2.tar.bz2
tar -xjf geos-3.4.2.tar.bz2
cd geos-3.4.2
CFLAGS="-m64 $CFLAGS" CPPFLAGS="-m64 $CPPFLAGS" CXXFLAGS="-m64 $CXXFLAGS" \
    FFLAGS="-m64 $FFLAGS" LDFLAGS="-m64 -L$HOME/lib -L/usr/lib64/ $LDFLAGS" \
    ./configure --prefix=$HOME
make
make install

############################################################
# Postgres (9.1.15)
# https://ftp.postgresql.org/pub/source/v9.1.15/postgresql-9.1.15.tar.bz2
############################################################
cd ~/src
wget https://ftp.postgresql.org/pub/source/v9.1.15/postgresql-9.1.15.tar.bz2
tar -xjf postgresql-9.1.15.tar.bz2
cd postgresql-9.1.15
CPPFLAGS="-I$HOME/include $CPPFLAGS" LDFLAGS="-L$HOME/lib -L/usr/lib64/ $LDFLAGS" \
    ./configure PYTHON="${PYTHON}" --prefix=$HOME --with-pgport=$PGPORT --with-python --disable-thread-safety
make
make install

############################################################
# PostGIS (2.1.5)
# http://download.osgeo.org/postgis/source/postgis-2.1.5.tar.gz
############################################################
cd ~/src
wget http://download.osgeo.org/postgis/source/postgis-2.1.5.tar.gz
tar -xzf postgis-2.1.5.tar.gz
cd postgis-2.1.5
CPPFLAGS="-I$HOME/include $CPPFLAGS" LDFLAGS="-L$HOME/lib -L/usr/lib64/ $LDFLAGS" \
    ./configure --prefix=$HOME \
                --with-gdalconfig=$HOME/bin/gdal-config \
                --with-geosconfig=$HOME/bin/geos-config \
                --with-jsondir=$HOME \
                --with-projdir=$HOME \
                --with-pgconfig=$HOME/bin/pg_config
make
make install

Okay, PostgreSQL should now be installed. After installation, you have some manual post-install setup and configuration to do:

#####################
# Post Installation #
#####################

# First, make sure that we're using the correct "psql", "createuser", and "createdb" commands:
export PATH="$HOME/bin:$PATH"
hash -r

# Add it to $HOME/.bashrc to make this permanent
echo 'export PATH="$HOME/bin:$PATH"' >> $HOME/.bashrc

# Set up DB location
mkdir $HOME/pgsql
$HOME/bin/initdb -D $HOME/pgsql/data

# Start postgresql server
$HOME/bin/postgres -D $HOME/pgsql/data >> $HOME/pgsql/log 2>&1 &

# Create the 'postgres' superuser
createuser -s postgres -P

# Create a database 'mydb'
createdb 'mydb'

# Now, connect to it (Use Ctrl-D to exit)
psql -U postgres mydb

# Create the PostGIS extension
CREATE EXTENSION postgis;

Hope that helps!

permanent link
This answer is marked "community wiki".

answered 16 Aug '12, 00:15

ryans ♦♦
5.0k93460
accept rate: 43%

edited 19 Mar '15, 06:26

Ryan, if you could add pgrouting to these instructions you would be my hero. I've been fighting with getting it installed for several days now. Your guide for Postgres/PostGIS was great though, so thank you for writing it.

(29 Dec '12, 22:32) jimmit

The build instructions for pgRouting look really simple and well-written, so yeah I'd be happy to include it when time permits.

(29 Dec '12, 23:01) ryans ♦♦

It doesn't work. It seems that pgRouting is broken, and the maintainers need to fix it, although it's also possible that I'm doing something wrong.

Specifically, the installation fails with a boost_astar function interface error in pgrouting/core/src/astar_boost_wrapper.cpp.

That seems to indicate that there's a problem with astar_search.hpp. I know that's being found though because $HOME/include/boost/graph/astar_search.hpp exists and the install confirms that it's finding boost in $HOME/include.

It's possible that pgRouting is simply not compatible with Boost 1.52.0, and you can try an older version perhaps.

If you're still interested in the install, it should look something like this:

# standard env vars
export TMPDIR=$HOME/tmp
export PATH="$HOME/bin:$PATH"
export C_INCLUDE_PATH="$HOME/include:$C_INCLUDE_PATH"
export LIBRARY_PATH="$HOME/lib:$LIBRARY_PATH"
export LD_LIBRARY_PATH="$HOME/lib:$LD_LIBRARY_PATH"

# boost is a C++ library, so we need this too:
export CPLUS_INCLUDE_PATH="$HOME/include:$CPLUS_INCLUDE_PATH"

############################################################
# Boost (1.52)
# http://sourceforge.net/projects/boost/files/
############################################################
cd ~/src
wget 'http://downloads.sourceforge.net/project/boost/boost/1.52.0/boost_1_52_0.tar.bz2'
tar -xjf boost_1_52_0.tar.bz2
cd boost_1_52_0
bash bootstrap.sh --prefix=$HOME
./b2 --prefix=$HOME
mv ./boost $HOME/include/
mv ./stage/lib $HOME/lib/boost

############################################################
# GAUL (0.1849-0)
# http://gaul.sourceforge.net/downloads.html
############################################################
cd ~/src
wget 'http://prdownloads.sourceforge.net/gaul/gaul-devel-0.1849-0.tar.bz2?download'
tar -xjf gaul-devel-0.1849-0.tar.bz2 
cd gaul-devel-0.1849-0
./configure --prefix=$HOME --enable-slang=no
make
make install

############################################################
# cmake (2.8.10)
# http://www.cmake.org/cmake/resources/software.html
############################################################
cd ~/src
wget 'http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz'
tar -xzf cmake-2.8.10.2.tar.gz
cd cmake-2.8.10.2
./configure --prefix=$HOME
make
make install

# ############################################################
# # CGAL (3.3.1)
# # http://www.cgal.org/download.html
# ############################################################
# cd ~/src
# wget 'https://gforge.inria.fr/frs/download.php/10694/CGAL-3.3.1.tar.gz'
# tar -xzf CGAL-3.3.1.tar.gz
# cd CGAL-3.3.1
# ./install_cgal --prefix=$HOME --with-boost=n --without-autofind -ni /usr/bin/g++
# export CGAL_MAKEFILE="/home/testweb310/share/cgal/cgal.mk"

############################################################
# GNU MP Bignum Library 5.0.2
############################################################
cd $HOME/src
wget 'http://mirror.ryansanden.com/gcc-4.6/gmp-5.0.2.tar.bz2'
tar -xjf gmp-5.0.2.tar.bz2
cd gmp-5.0.2
CPPFLAGS=-fexceptions ./configure --prefix=$HOME --enable-cxx
make          # 2 min
make install

############################################################
# GNU MFPR Library 3.1.0
############################################################
cd $HOME/src
wget 'http://mirror.ryansanden.com/gcc-4.6/mpfr-3.1.0.tar.bz2'
wget 'http://mirror.ryansanden.com/gcc-4.6/mpfr-3.1.0-allpatches.patch'
tar -xjf mpfr-3.1.0.tar.bz2
cd mpfr-3.1.0
patch -N -Z -p1 < ../mpfr-3.1.0-allpatches.patch
./configure --prefix=$HOME --with-gmp=$HOME/
make          # 1.5 min
make install

############################################################
# CGAL (4.1)
# http://www.cgal.org/download.html
############################################################
cd ~/src
wget 'https://gforge.inria.fr/frs/download.php/31640/CGAL-4.1.tar.bz2'
tar -xjf CGAL-4.1.tar.bz2
cd CGAL-4.1
cmake -DBOOST_ROOT="$HOME" \
      -DWITH_GMP="y" -DGMP_INCLUDE_DIR="$HOME/include" -DGMP_LIBRARIES_DIR="$HOME/lib" \
      -DMPFR_INCLUDE_DIR="$HOME/include" -DMPFR_LIBRARIES_DIR="$HOME/lib" \
      -DCMAKE_INSTALL_PREFIX="$HOME" .
make
make install

############################################################
# pgrouting (1.05)
# http://pgrouting.org/download.html
############################################################
export CPPFLAGS="-I$HOME/include $CPPFLAGS"
export LDFLAGS="-L$HOME/lib $LDFLAGS"

cd ~/src
git clone git://github.com/pgRouting/pgrouting.git pgrouting
cd pgrouting
mkdir -p $HOME/share/pgrouting

sed -i "s^/usr/share/pgrouting^$HOME/share/pgrouting^g" CMakeLists.txt
sed -i "s^/usr^$HOME^g" ./cmake/FindCGAL.cmake
sed -i "s^/usr^$HOME^g" ./cmake/FindGAUL.cmake
sed -i "s^/usr^$HOME^g" ./cmake/FindPostgreSQL.cmake
cmake -DPOSTGRESQL_EXECUTABLE="$HOME/bin" \
      -DBoost_INCLUDE_DIR="$HOME/include" \
      -DBOOST_THREAD_LIBRARIES="$HOME/lib" \
      -DWITH_TSP="ON" -DWITH_DD="ON" -Wno-dev .
make

# also tried this instead of last three sed lines:
# 
# cmake -DPOSTGRESQL_INCLUDE_DIR="$HOME/include/postgresql/server" -DPOSTGRESQL_LIBRARIES="$HOME/lib" \
#       -DPOSTGRESQL_EXECUTABLE="$HOME/bin" \
#       -DBoost_INCLUDE_DIR="$HOME/include" \
#       -DBOOST_THREAD_LIBRARIES="$HOME/lib" \
#       -DGAUL_INCLUDE_DIR="$HOME/include" -DGAUL_LIBRARIES="$HOME/lib" -DGAUL_UTIL_LIBRARIES="$HOME/lib" \
#       -DCGAL_INCLUDE_DIR="$HOME/include" -DCGAL_LIBRARIES="$HOME/lib" \
#       -DSQL_INSTALL_PATH="$HOME/share/postlbs" \
#       -DLIB_DIR="$HOME/lib" \
#       -DWITH_TSP="ON" -DWITH_DD="ON" -Wno-dev .
(30 Dec '12, 20:54) ryans ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×109
×9

question asked: 16 Aug '12, 00:06

question was seen: 7,839 times

last updated: 19 Mar '15, 06:31

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM