Installing and configuring CouchDB

CouchDB is a database that uses JSON for documents, JavaScript for MapReduce queries, and regular HTTP for an API

UPDATE: See the addendum at the bottom of the page for a full update of how to get couchdb running after reboot. You still need to follow these instructions, then pop down the bottom for final piece of the puzzle

I struggled with this several times, until a colleague of mine called Stephen Lock showed me the light, so shout out to him for showing me how to make it work post install.

sudo apt-get install couchdb

UPDATE: The latest version no longer fails and you end up with the last view lines of you console looking like

[ ok ] Starting database server: couchdb.
Setting up wwwconfig-common (0.2.2) ...
Setting up javascript-common (7) ...
Setting up libsctp1 (1.0.11+dfsg-2) ...
Setting up lksctp-tools (1.0.11+dfsg-2) ...
Processing triggers for menu ...

If you do get an error, then its probably the problem reported in at the bottom of this blog, but now we can just continue by making sure couch is binding to the correct IP address so we can connect to it from another machine

cd /etc/couchdb
sudo vi local.ini

To change the bind_address to the address of the machine you are installing on, look for the following line

;bind_address = 127.0.0.1

Remove the ; from the beginning and then change the ip address to the address of the server on which couch is installed. Finall restart the couchdb service

/etc/init.d/couchdb restart

This time you’ll see the following line which signifies Couch is up and running

[ ok ] Starting database server: couchdb.

To check its all working, open a browser and enter the url http://hostname:5984 and you’ll see a single line of text along the lines of

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

We can then bring up the admin console by entering in a browser, the url http://hostname:5984/_utils which will show something like this

If install fails

When this is finished it will probably report an error that it couldn’t start couch. Typically the install will finish with the following lines

[....] Starting database server: couchdbApache CouchDB needs write permission on the PID file: /var/run/couchdb/couchdb.pid
 failed!
invoke-rc.d: initscript couchdb, action "start" failed.
dpkg: error processing couchdb (--configure):
 subprocess installed post-installation script returned error exit status 1
Setting up libsctp1 (1.0.11+dfsg-2) ...
Setting up lksctp-tools (1.0.11+dfsg-2) ...
Processing triggers for menu ...
Errors were encountered while processing:
 couchdb
E: Sub-process /usr/bin/dpkg returned an error code (1)

Don’t panic !, we just need to do some jiggery-pokery to set the permissions and ip addresses that couch uses. First we need to make sure that couch owns the right folders which are not set correctly during install

sudo chown couchdb:couchdb -R /var/lib/couchdb /var/log/couchdb /var/run/couchdb
sudo update-rc.d couchdb defaults

Then we need to make sure couch is binding to the correct IP address so we can connect to it from another machine

cd /etc/couchdb
sudo vi local.ini

To change the bind_address to the address of the machine you are installing on, look for the following line

;bind_address = 127.0.0.1

Remove the ; from the beginning and then change the ip address to the address of the server on which couch is installed. Finall restart the couchdb service

/etc/init.d/couchdb start

This time you’ll see the following line which signifies Couch is up and running

[ ok ] Starting database server: couchdb.

To check its all working, open a browser and enter the url http://hostname:5984 and you’ll see a single line of text along the lines of

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

We can then bring up the admin console by entering in a browser, the url http://hostname:5984/_utils which will show something like this

 

 

Addendum

I’ve had problems with couchdb starting because of permissions and searching the internet shows this to be a common bug with the current version and is because /var/run/couchdb has its permissions set back to root after reboot. The easiet way to fix this for now is to modiy rc.local and make it reset the permissions on startup

sudo vi /etc/init.d/couchdb

And look for the method that starts with the following at about line 84

start_couchdb () {

Add a new line after mkdir -P “$RUN_DIR”
and add the following

start_couchdb () {
    # Start Apache CouchDB as a background process.

    mkdir -P "$RUN_DIR"

    #Add this line
    chown couchdb:couchdb -R "$RUN_DIR"

    command="$COUCHDB -b"
Tobias

You can also put the permission fixing in /etc/default/couchdb by adding these lines to that file:
mkdir -p “$RUN_DIR”
chown couchdb “$RUN_DIR” -R

Michael Heuberger

Hello guys

I’m afraid I still have issues with the CouchDB installation. Similar ones like above for version 1.2.0-2ubuntu1.

After apt-get install couchdb there were problems, see below.

Any hints guys?

Cheers
Michael

xx@yy /etc/default> sudo dpkg –configure couchdb
Setting up couchdb (1.2.0-2ubuntu1) …
invoke-rc.d: initscript couchdb, action “start” failed.
dpkg: error processing couchdb (–configure):
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
couchdb

javier

Hi,

I use Couchdb with PHPillow but I can’t connect it with the Couchdb. I’ve poblems of permissions denied

Can anyone help?

gmas

Another thing you might want to look at if couchdb doesn’t start after reboot is whether the directory /var/log/couchdb/ exists and is owned by couchdb user.

Anders

Hi,
thanks for a great guide! Worked right away for me, but I ran into one problem when trying to restart after having changed the bind address. When attempting the /etc/init.d/couchdb restart I am promted for a couchdbPassword. I haven’t configured any during the install process. What to do?

It says
$/etc/init.d/couchdb restart
[….] Restarting database server: couchdbPassword:
su: Authentication failure
Password:
su: Authentication failure
failed!

The last lines is me trying to guess passwords and failing.

Any advice?

Many thanks again!

Your email address will not be published. Required fields are marked *