getting started with couchdb running behind apache on os x

Tue, Nov 3, 2009

I’ve started to tinker with CouchDB so here’s how to get up and running from the source distro. This is how I built everything from source on OS X.

Download Erlang from here and build it from source. The touch bit is to disable widgets otherwise you get a nasty error.

./configure –prefix=/Users/alistair/apps/erlang
touch lib/wx/SKIP
make
make install
Download SpiderMonkey from here. Build it from source. The following is adapted from this script.
#!/bin/bash

mkdir -p /Users/alistair/apps/spidermonkey mkdir -p /Users/alistair/apps/spidermonkey/include mkdir -p /Users/alistair/apps/spidermonkey/lib mkdir -p /Users/alistair/apps/spidermonkey/bin

cd src make BUILD_OPT=1 -f Makefile.ref

cp *.h /Users/alistair/apps/spidermonkey/include cp *.tbl /Users/alistair/apps/spidermonkey/include

cd Darwin_OPT.OBJ

cp *.h /Users/alistair/apps/spidermonkey/include cp js /Users/alistair/apps/spidermonkey/bin cp libjs.dylib /Users/alistair/apps/spidermonkey/lib

Download ICU from here. Build it from source:
cd source
./configure –prefix=/Users/alistair/apps/icu
make
make install
Add icu/bin to your path before continuing.

Download CouchDB from here. Build it from source:

./configure –prefix=/Users/alistair/apps/couchdb 
–with-js-include=/Users/alistair/apps/spidermonkey/include
–with-js-lib=/Users/alistair/apps/spidermonkey/lib
–with-erlang=/Users/alistair/apps/erlang/lib/erlang/usr/include make make install
Download Apache from here. Build it from source:
./configure –enable-layout=Sgarbh  
–enable-rewrite
–enable-so
–enable-ssl
–enable-proxy
–enable-proxy-http make make install
then configure CouchDB in Apache’s httpd.conf or extra/httpd-vhosts.conf:
<VirtualHost *:8091>
  …
  <Proxy http://localhost:5984/>
    Order deny,allow
    Allow from all
  </Proxy>

ProxyRequests Off ProxyPreserveHost Off AllowEncodedSlashes On KeepAlive Off

ProxyPass /couchdb/ http://localhost:5984/ nocanon ProxyPassReverse /couchdb/ http://localhost:5984/

</VirtualHost>

Start CouchDB:
cd /Users/alistair/apps/couchdb-0.10.0/bin
./couchdb status
Point your browser to:
http://your.domain.com/couchdb/_utils/
Now that you have CouchDB installed, it’s time to play around with it. Here is some ruby to get you started:
require ‘net/http’

class CouchKit attr_reader :couchdb_server

def initialize(url) @couchdb_server = url end

def create(db_name) potato(“PUT”, db_name) end

def delete(db_name) potato(“DELETE”, db_name) end

def info(db_name) potato(“GET”, db_name) end

def add_doc(db_name, doc_id, doc_json) potato(“PUT”, “#{db_name}/#{doc_id}“, doc_json) end

def get_doc(db_name, doc_id) potato(“GET”, “#{db_name}/#{doc_id}“) end

def potato(mode, db_name, data=“”) uri = URI.parse(“#{@couchdb_server}/#{db_name}“) Net::HTTP.start(uri.host, uri.port) do |http| headers = {‘Content-Type’ => ‘text/plain; charset=utf-8’} response = http.send_request(“#{mode}”, uri.request_uri, data, headers) puts “Response #{response.code} #{response.message}: #{response.body}” end end end

require ‘ck’

couchdb_server = “http://your.domain.com/couchdb" test_db_name = “testdb” test_doc_id = 111 test_doc = <<-EOS { “Subject”:“I like Cakes!”, “Author”:“codeBrane”, “PostedDate”:“2009-11-03T17:30:12-04:00”, “Tags”:[“cakes”, “eating”, “munching”], “Body”:“I do like eating cakes you know!” } EOS

cdb = CouchKit.new(couchdb_server)

cdb.create(test_db_name) puts “——————-”

cdb.info(test_db_name) puts “——————-”

cdb.add_doc(test_db_name, test_doc_id, test_doc) puts “——————-”

cdb.get_doc(test_db_name, test_doc_id) puts “——————-”

cdb.delete(test_db_name)

You should see similar outpout to the following:

CouchDB in action

njoy reading the CouchDB API reference!

comments powered by Disqus