Drupal 6 on Mac with PostGIS

For an experimental spatial PostGIS database I needed to set up Drupal to manage the data entry. Drupal by default installs with mySQL, so to run it with PostgreSQL, which allows me to add the PostGIS language I needed to take a longer route.

Here is how it worked.

1. PHP and Apache
Make sure your PHP has PostgreSQL support. The default PHP install on the Mac does not have it.

Here is a module that is compiled with the appropriate configuration.
http://www.entropy.ch/software/macosx/php/ (Note: It is not clear if this runs on Snow Leopard )

Otherwise you'll have to download the source and compile PHP for PostgreSQL support, then uncomment line 114 in /etc/apache2/httpd.conf to enable Leopard's built-in PHP:
LoadModule php5_module libexec/apache2/libphp5.so

(re)start Apache, either through the system preferences > sharing or via commandline
sudo apachectl start or
sudo apachectl restart

2. Database
Install PostgreSQL 8.4.3-1 and PostGIS 1.5.1-1 for Postgres 8.4 from http://www.kyngchaos.com/software:postgres
(Install PROJ and GEOS frameworks from http://www.kyngchaos.com/software/frameworks if needed)

Create Drupal user (Note: the way the command is issued has to do with the way roles and users are set up in the Kynchaos install. See the Readme file that comes with it)
sudo su - postgres -c '/usr/local/pgsql/bin/createuser drupal --pwprompt --encrypted'

Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) n
Shall the new role be allowed to create more new roles? (y/n) n

Create Drupal database
sudo su - postgres -c ' /usr/local/pgsql/bin/createdb drupal --owner=drupal'

Set it up for PostGIS
sudo su - postgres -c '/usr/local/pgsql/bin/createlang plpgsql drupal'
sudo su - postgres -c '/usr/local/pgsql/bin/psql -d drupal -f /usr/local/pgsql/share/contrib/postgis-1.5/postgis.sql'
sudo su - postgres -c '/usr/local/pgsql/bin/psql -d drupal -f /usr/local/pgsql/share/contrib/postgis-1.5/spatial_ref_sys.sql'

3. Drupal
Download Drupal into /Library/WebServer/Documents/drupal
Create ./sites/default/files folder
Change permissions
chmod 777 /Library/WebServer/Documents/drupal/sites/default/files

Copy the ./sites/default/default.settings.php file to ./sites/default/settings.php then edit:

$db_url = "pgsql://drupal:YourPassWord@localhost/drupal";

Point browser to http://localhost/drupal/install.php

References
http://www.sysarchitects.com/node/58
http://pgedit.com/install_drupal

No TweetBacks yet. (Be the first to Tweet this post)