Install CouchDB on Ubuntu/Debian with Lighttpd

Depending on your version of Ubuntu ~ Debian, you may be able to install the latest version of CouchDB via APTITUDE; chances are though, you wont.
As its really not that difficult to install it from scratch we may as well do it from source.

Here we'll cover the installation; basic configuration and how to proxy a sub-domain to your CouchDB.

I'll stick the commands below in order of sequence (how the bloody hell else would you do it?)

Step One: Install all the required crap…

aptitude install automake spidermonkey-bin autoconf subversion-tools libtool help2man build-essential erlang erlang-manpages libicu38 libmozjs-dev wget libicu-dev libreadline5-dev checkinstall  

*Note: add sudo to the front of this if you usually use the sudo command. * If your on Ubuntu 8.04 or Intrepid you'll need to have a fiddle after this to get the latest version of erlang or when you download CouchDB, it will tell you to sod off.
To make sure your not one of these people type erl into shell;

root@vm000:/# erl  
Erlang (BEAM) emulator version 5.6.5 [source] [64-bit] [async-threads:0] [kernel-poll:false]

Eshell V5.6.5  (abort with ^G)  
1>  

If your version is 5.6.5 it will work fine with version 0.11.0 at least; If you have any difficulties it will tell you which version you need.
Now if its less than 5.6.5 lets update;

nano /etc/apt/sources.list  

And comment out your normal "universe" then add the latest…

#deb http://uk.archive.ubuntu.com/ubuntu/ hardy main restricted universe
deb http://uk.archive.ubuntu.com/ubuntu/ jaunty universe  

Then update your aptitude; then upgrade erlang

apt-get update  
apt-get upgrade erlang  

Check the version again (as we did a moment ago) if your on 5.6.5, feel free to re-edit your sources.list file commenting out jaunty for hardy.
Ubuntu 8.0.4 is the STABLE server release and is under LONG TERM SUPPORT; so those instructions will apply to many people :)

Step Two: Get the latest version of CouchDB onto your server

Go to http://couchdb.apache.org/downloads.html and copy the url for the latest version. Then unzip it.

wget http://mirrors.enquira.co.uk/apache/couchdb/0.11.0/apache-couchdb-0.11.0.tar.gz  
tar -xzvf apache-couchdb-0.11.0.tar.gz  

Step Three: Create a user for your settee

sudo adduser --no-create-home --disabled-password --disabled-login couchdb  

Step Four: Lets install CouchDB

Good shell; lets go on. Within your extracted tar file…
You may want a beer at this point.

cd apache-couchdb  
./configure --bindir=/usr/bin --sbindir=/usr/sbin --localstatedir=/var --sysconfdir=/etc
make  
make install  

Note: Again you'll need SUDO for the make command; if you've used your brains you'll have used sudo su, entered your password and not had to enter it again… just a suggestion.
Bit of permission prodding:

chown couchdb:couchdb -R /var/lib/couchdb /var/log/couchdb  
update-rc.d couchdb defaults  
# Service start
/etc/init.d/couchdb start

Test your install:

curl 127.0.0.1:5984  
{"couchdb":"Welcome","version":"0.11.0"}

Yey its running
By default CouchDB will run on port 5984; you can easily change that by going to the config…

nano /etc/couchdb/default.ini  
#inside the file
[httpd]
port = 5984  
bind_address = 127.0.0.1  

As you can see its also bound to your localhost (much like the default MYSQL install) so at the moment you can only access your CouchDB installer locally.
Now if you want to just expose it on the same port chance bind_address to your server ip and you can see it working on http://yourip:5984
You may need to open up your Firewall first though as follows...

iptables -A INPUT -p tcp -i eth0 --dport 5984 -m state --state NEW -j ACCEPT  

Stuff direct access, give me that Lighttpd config you promised

Ok, OK! Its quick and painless and means you can leave your install bound to the localhost; it also allows you to access the site on a standard web-port rather then finding your shit stops working every-time you step behind a firewall.

So lets add this config to our Lighttpd config:

$HTTP["host"] == "couchdatabase.mydomain.com" {
    proxy.server = (
        "/" => (("host" => "127.0.0.1", "port" => 5984)) 
    )
}    

Restart Lighttpd
root@vm000:~# /etc/init.d/lighttpd restart

Try pinging your domain and if it goes where you've set it up to go (domain propogration is boring) then you can test it out;
couchdatabase.mydomain.com should display
and http://couchdatabase.mydomain.com/

{"couchdb":"Welcome","version":"0.11.0"}

and http://couchdatabase.mydomain.com/utils/index.html brings up the admin
and your JSON JS file - http://couchdatabase.mydomain.com/
utils/script/json2.js

Installing on Windows (doesn't deserve an entire post)

(Tested on Windows 7 64bit) Go to http://wiki.apache.org/couchdb/Windowsbinaryinstaller and download the installer; run; as of 0.11.0 it installs the Windows Service for you as well.

Chris McKee

Chris McKee

https://chrismckee.co.uk

Software Engineer, Web Front/Backend/Architecture; all-round tech obsessed geek. I hate unnecessary optimism

View Comments