Installing PostGIS 1.2.0 with MacPorts PostgreSQL 8.1

In the previous post I detailed how to install PostgreSQL with MacPorts. This time we will see how to get the latest PostGIS (version 1.2.0 as of this writing) installed.

MacPorts provide PostGIS 1.1.1 but it depends on postgresql8 and we decided to go for the postgresql81 version last time. So we’ll have some handwork to get all run together.

First install proj and geos from MacPorts

sudo port install proj
sudo port install geos

then download, extract, compile and install PostGIS 1.2.0 :

curl -O http://postgis.refractions.net/download/postgis-1.2.0.tar.gz
tar xvzf postgis-1.2.0.tar.gz
cd postgis-1.2.0
./configure --libdir=/opt/local/lib/postgresql81/ --datadir=/opt/local/share/postgis --with-pgsql=/opt/local/lib/postgresql81/bin/pg_config --with-geos=/opt/local/bin/geos-config --with-prog=/opt/local/
make
sudo make install

Here we are, PostGIS 1.2.0 installed on a PostgreSQL 8.1.

Now every time you need to use PostGIS functions you need to configure your database (every new database need an “enabling phase”. You can use a template, but I will not cover this part) as follow :

createlang plpgsql yourdatabase
psql -f /opt/local/share/postgis/lwpostgis.sql -d your_database
psql -f /opt/local/share/postgis/spatial_ref_sys.sql -d your_database

[Update (04/01/2008) : Add missing /share/ in paths. thanks Galen]

If you already had an old version of PostGIS installed and want to upgrade your databases, follow the “UPGRADING EXISTING SPATIAL DATABASES” parts of PostGIS README.postgis.[…]

Published on Wed, 20 Dec 2006 11:47

PostgreSQL, MySQL and Ruby Drivers with MacPorts

If you’re on MacOS X and you’re developing database aware applications you certainly want to have installed locally one or both of those populars RDBMS : PostgreSQL or MySQL.

My prefered way of doing it is through MacPorts (previously known as DarwinPorts), a package manager designed initially for Darwin and now focusing on MacOS X.

I assume you already have installed MacPorts as explain on their website.

So let’s open a console with your favorite application (I tend to prefer iTerm over Terminal.app) and enter those commands :

sudo port install mysql5 +server

this will install MySQL 5.x database and the launchd script needed to start it (on-demand or at startup).
When the installation is done you’ll be asked to install the launchd script, just ignore this part and jump to the initialization part.

To initialize MySQL and secure access to it, just enter those commands

sudo -u mysql mysql_install_db5
sudo -u mysql /opt/local/lib/mysql5/bin/mysqld_safe &
/opt/local/lib/mysql5/bin/mysqladmin -u root password 'your_password'

You should now have a shinny new MySQL 5 installation with a password for your root account.

Then PostgreSQL, let’s type in :

sudo port install postgresql81-server

this will install PostgreSQL 8.1.x database and its launchd script.
When the installation is done, as with MySQL skip the launchd part and go to the initialization by issuing those commands :

sudo mkdir -p /opt/local/var/db/postgresql81/defaultdb
sudo chown postgres81:postgres /opt/local/var/db/postgresql81/defaultdb
sudo su postgres81 -c '/opt/local/lib/postgresql81/bin/initdb -D /opt/local/var/db/postgresql81/defaultdb'

PostgreSQL access authorization is something beyond this article, so I’ll don’t cover it.

If all goes well you should now have 2 working installations, but no simple way to start/stop them. A simple and powerful way of handling this (and launchd scripts, create/edit/load/unload) is Lingon. Just download the last version and go to the “Users Daemons” tab and you will see your two launchd scripts are there waiting for you to load/unload/enable/disable them.

To finish this installation, if you’re a Ruby kind of guy you probably want to access those databases from it. There are two ways to install the needed libraries : MacPorts or RubyGems.

For MySQL, there is no problem with MacPorts just type :

sudo port install rb-mysql

If you prefer the RubyGems solution the command is little more tricky :

sudo gem install mysql -- --with-mysql-config=/opt/local/bin/mysql_config5

[Update]
For MacOS X.5 (Leopard) stock Ruby 1.8.6 :

sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/opt/local/bin/mysql_config5

For PostgreSQL, you can’t do it through MacPorts unless you choose to install postgresql8 (and not postgresql81), because of the dependencies. But you can install the library through RubyGems with :

 sudo gem install postgres -- --with-pgsql-include-dir=/opt/local/include/postgresql81/ --with-pgsql-lib-dir=/opt/local/lib/postgresql81/ 

[Update]
For MacOS X.5 (Leopard) stock Ruby 1.8.6 :

 sudo env ARCHFLAGS="-arch i386" gem install postgres -- --with-pgsql-include=/opt/local/include/postgresql81/ --with-pgsql-lib=/opt/local/lib/postgresql81/ 

This is a simple and yet functional setup to work.[…]

Published on Sun, 19 Nov 2006 12:06

RSS