====== CouchDB ======
[[http://incubator.apache.org/couchdb/|CouchDB]] is a document-oriented database with an API interface. It is good for databases that don't need a strict schema. Because it is currently under development, it must be installed from source. This also means the ride can be a little bumpy.
These instructions pertain to the 0.8.1-incubating version of CouchDB.
CouchDB is under rapid development, so installation instructions may become outdated without notice. Also, do not upgrade CouchDB to the latest revision without testing locally first, since the API is evolving.
===== Installing prerequisites =====
While erlang can be built as a 64-bit application, it does not seem to work with openssl under this configuration. They work around is to build everything as 32-bit even though the Accelerators are 64-bit systems.
==== openssl ====
Install openssl in /opt/local/32 or some other location if you already have the 64-bit library installed for things like [[accelerators:nginx_apache_proxy?s=openssl|nginx]].
cd /tmp
curl -O http://www.openssl.org/source/openssl-0.9.8e.tar.gz
tar xzf openssl-0.9.8e.tar.gz
cd openssl-0.9.8e
./Configure --prefix=/opt/local/32 386 shared solaris-x86-gcc
gmake
gmake test
sudo gmake install
==== erlang ====
[[http://www.erlang.org/|Erlang]] is a programming language for concurrent and distributed sytems. CouchDB is written in erlang. The ''--with-ssl'' flag should point to the directory where you installed the 32-bit openssl.
cd /tmp
curl -O http://www.erlang.org/download/otp_src_R12B-2.tar.gz
tar xzf otp_src_R12B-2.tar.gz
cd otp_src_R12B-2
./configure --prefix=/opt/local --with-ssl=/opt/local/32
gmake
sudo gmake install
=== Check erlang ===
Once erlang is installed, check whether it and its cryptography library are functioning correctly.
$ erl
Erlang (BEAM) emulator version 5.6.2 [source] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.6.2 (abort with ^G)
1> crypto:start().
ok
2> q().
ok
==== ICU ====
[[http://icu-project.org|ICU]] is an internationalization library.
On 5th november 2008, icu4c-4_0_d02-src seems to have moved to obsolete-d-releases folder. I'll try to install from icu4c-4_0-src.tgz instead but I'm not sure it will work, hence I keep the initial reference here
./runConfigureICU SolarisX86 --prefix=/opt/local does not work out of the box on my re-imaged pkgsrc Accelerator. I try ./runConfigureICU Solaris/GCC --prefix=/opt/local instead
cd /tmp
curl -O http://download.icu-project.org/files/icu4c/4.0/icu4c-4_0_d02-src.tgz
tar xzf icu4c-4_0_d02-src.tgz
cd icu/source
chmod +x runConfigureICU configure install-sh
./runConfigureICU SolarisX86 --prefix=/opt/local
./configure --prefix=/opt/local
gmake
sudo gmake install
==== SpiderMonkey ====
[[http://www.mozilla.org/js/spidermonkey/|SpiderMonkey]] is the Javascript engine from Firefox.
Download the source code:
cd /tmp
curl -O http://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz
tar xzf js-1.7.0.tar.gz
cd js/src
There is no makefile specific to the OpenSolaris architecture. Make one by creating a symlink to the default SunOS one.
cd config
ln -s SunOS5.5.mk SunOS5.11_i86pc.mk
By default, the makefile will use the Sun build tools. We want to use the GNU tools instead. Open ''SunOS5.5.mk'' and change the lines
ifndef NS_USE_NATIVE
CC = gcc
CCC = g++
CFLAGS += -Wall -Wno-format
else
CC = cc
CCC = CC
endif
to instead read
#ifndef NS_USE_NATIVE
CC = gcc
CCC = g++
CFLAGS += -Wall -Wno-format
#else
#CC = cc
#CCC = CC
#endif
Build and install SpiderMonkey:
cd ..
rm lock_SunOS.s
gmake -f Makefile.ref
sudo JS_DIST=/opt/local/spidermonkey gmake -f Makefile.ref export
===== Installing CouchDB =====
To install CouchDB, download the stable version or checkout latest source code and configure it using the dependencies installed above.
==== Latest "stable" version ====
cd /tmp
curl -O http://www.mirrorservice.org/sites/ftp.apache.org/incubator/couchdb/0.8.1-incubating/apache-couchdb-0.8.1-incubating.tar.gz
tar xzf apache-couchdb-0.8.1-incubating.tar.gz
cd apache-couchdb-0.8.1-incubating
./configure --prefix=/opt/local --with-js-include=/opt/local/spidermonkey/include --with-js-lib=/opt/local/spidermonkey/lib --with-erlang=/opt/local/lib/erlang/usr/include
gmake
sudo gmake install
==== From SVN ====
cd /tmp
svn co http://svn.apache.org/repos/asf/incubator/couchdb/trunk couchdb
cd couchdb
bash bootstrap
./configure --prefix=/opt/local --with-js-include=/opt/local/spidermonkey/include --with-js-lib=/opt/local/spidermonkey/lib --with-erlang=/opt/local/lib/erlang/usr/include
gmake
sudo gmake install
===== Configuration and Setup =====
The user who runs the CouchDB server needs to have write access to a few key directories: ''/opt/local/var/lib/couchdb'' and ''/opt/local/var/run/couchdb''. You can either [[accelerators:kb:users#creating-users|create a new user]] or run CouchDB as the ''nobody'' user.
Secondly, the user running CouchDB must have the environment variable ''LD_LIBRARY_PATH'' set to ''/opt/local/lib:/opt/local/spidermonkey/lib'', or to whichever directories you installed ICU and SpiderMonkey, respectively. This is easily done using [[solaris:smf-manifest-recipes#couchdb|SMF, as shown in the example manifest]].
To ensure that CouchDB is listening on ''localhost'' only, in ''/opt/local/etc/couchdb/couch.ini'' make sure you are binding to localhost:
BindAddress=127.0.0.1
CouchDB has not implemented a security model yet, so any user on your system potentially has access to any CouchDB database. More importantly, if you do not bind CouchDB to ''localhost'', any remote user can access the database directly.
Assuming you are running CouchDB as the user ''couchdb'', you can test the server by issuing the command
echo LD_LIBRARY_PATH=/opt/local/lib:/opt/local/spidermonkey/lib couchdb | sudo -u couchdb bash
Once CouchDB has started, test that it is working:
curl http://localhost:5984
{"couchdb":"Welcome","version":"0.8.1-incubating"}
=== Common Problems ===
If you see
couch 0.7.3a662495 (LogLevel=info)
Apache CouchDB is starting.
{"init terminating in do_boot",{error,{open_error,-10}}}
init terminating in do_boot ()
or
Apache CouchDB 0.8.1-incubating (LogLevel=info)
Apache CouchDB is starting.
{"init terminating in do_boot","ld.so.1: beam: fatal: libjs.so: open failed: No such file or directory"}
when CouchDB is starting, it is because the ''LD_LIBRARY_PATH'' is not set as above.
The output
{"init terminating in
do_boot",{undef,[{crypto,start,[]},{erl_eval,do_apply,5},{init,start_it,1},{init,start_em,1}]}}
means that there is a problem with the OpenSSL library.
===== Installing versions prior to 0.8.1 =====
=== Make CouchDB play nice on Solaris ===
The CouchDB programs, ''couchdb'' and ''couchjs'' are actually shell scripts. In versions of CouchDB prior to 0.8.1 (that is, 0.7.3 and 0.8.0), you need to make a few small modifications to make them work without issue on OpenSolaris.
These scripts will be in ''/opt/local/bin''. In both ''couchdb'' and ''couchjs'', replace the first line ''#!/bin/sh -e'' with ''#!/bin/bash''. In ''couchdb'', change all instances of ''awk'' to ''nawk''
=== Other bugs ===
There is a bug in CouchDB 0.8.0 (that seems fixed in 0.8.1) that prevents file paths in the configuration file to be properly replaced in OpenSolaris. Assuming you have installed in ''/opt/local'', update ''/opt/local/etc/couchdb/couch.ini'' to read
; etc/couchdb/couch.ini.tpl. Generated from couch.ini.tpl.in by configure.
[Couch]
ConsoleStartupMsg=Apache CouchDB is starting.
DbRootDir=/opt/local/var/lib/couchdb
Port=5984
BindAddress=127.0.0.1
DocumentRoot=/opt/local/share/couchdb/www
LogFile=/opt/local/var/log/couchdb/couch.log
UtilDriverDir=/opt/local/lib/couchdb/erlang/lib/couch-0.8.0-incubating/priv/lib
LogLevel=info
[Couch Query Servers]
javascript=/opt/local/bin/couchjs /opt/local/share/couchdb/server/main.js