Ubuntu Hardy - Rails and PHP options for PostgreSQL

Ruby on Rails and PHP are popular web application frameworks; both commonly make use of a database server on the back-end.

This article will cover installation of the packages needed to integrate PostgreSQL with Ruby on Rails and a standard PHP install.

PostgreSQL and Ruby on Rails

I am assuming you have Ruby on Rails installed at this point. If not, please review the Ubuntu Hardy - Ruby on Rails article and the PostgreSQL installation article.

We only need to install a single package:

sudo aptitude install libpgsql-ruby1.8

Let's check if it's working properly:

irb(main):001:0> require 'postgres'
=> true
irb(main):002:0> exit

Great! That's all you need to have Rails and PostgreSQL work together.

PostgreSQL and PHP

If you installed Apache and PHP using the Ubuntu Hardy - Apache and PHP article, then you only need to install the the PHP PostgreSQL module:

sudo aptitude install php5-pgsql

A standard phpinfo page shows the following information for the pgsql module:

phpinfo pgsql information

As you can see, installation is very easy.


Installing the packages necessary for PostgreSQL to integrate with Ruby on Rails and PHP is a simple process — allowing you to concentrate on site design rather than the installation itself. A big plus!


Article Comments:

Simone Carletti commented Sun Aug 02 22:46:09 UTC 2009:

The Ruby 'postgres' GEM has been deprecated in favor of 'pg'. See http://wiki.rubyonrails.org/database-support/postgres

You simply need to install the postgresql package, then run

$ sudo gem install pg

(make sure the GEM can find the path to the PG binary running pg_config --bindir)

Want to comment?

(not made public)


(use plain text or Markdown syntax)