• Tutorials
  • HOWTO Install CouchDB 3.1.1 on Opalstack

This is a WIP.

At this time, the latest stable version of CouchDB is 3.1.1. The CouchDB Unix Installation doc assumes the installer can use sudo, which is not the case for regular Opalstack users, so the process will be slightly different on Opalstack.

Fortunately, the folks at Webfaction wrote a tutorial on installing CouchDB 1.1.1 on Webfaction. This tutorial borrows liberally from that one.

First, we need to install some dependencies. Although Opalstack has Erlang and OTP installed on its servers, the version (OTP 23) is incompatible with CouchDB 3.1.1. OTP 22.3 is the latest OTP version that will work for us.

Also, we could install firefox 60.9.0, but it requires a newer version of gcc than Opalstack has installed, so we'll use spidermonkey 1.8.5.

You may want to put the following in a file called buildcouch1of2.sh:

export PATH="$HOME/bin:$PATH"
mkdir -p $HOME/src
mkdir -p $HOME/opt

# erlang & otp 22.3 - source: https://erlang.org/download/otp_src_22.3.tar.gz
cd $HOME/src
wget 'https://erlang.org/download/otp_src_22.3.tar.gz'
tar -xzf otp_src_22.3.tar.gz
cd otp_src_22.3
./configure --prefix=$HOME
make
make install

# spidermonkey 1.8.5 - source: https://ftp.mozilla.org/pub/mozilla.org/js/js185-1.0.0.tar.gz
cd $HOME/src
wget 'https://ftp.mozilla.org/pub/mozilla.org/js/js185-1.0.0.tar.gz'
tar -xzf js185-1.0.0.tar.gz
cd js-1.8.5/js/src
./configure --prefix=$HOME
make
make install

# couchdb 3.1.1 - source: https://downloads.apache.org/couchdb/source/3.1.1/apache-couchdb-3.1.1.tar.gz
cd $HOME/src
wget 'https://downloads.apache.org/couchdb/source/3.1.1/apache-couchdb-3.1.1.tar.gz'
tar -xzf apache-couchdb-3.1.1.tar.gz
cd apache-couchdb-3.1.1

echo Step 1 of 2 complete
echo Edit line 111 of ~/src/apache-couchdb-3.1.1/src/couch/rebar.config.script before running step 2 of 2

Run the preceding commands. They will install OTP 22.3 and Spidermonkey 1.8.5 and download and unzip the CouchDB 3.1.1 source. Unfortunately, I was not able to get CouchDB to find Spidermonkey via any of multiple combinations of command line options, even after asking in #couchdb on freenode and couchdb.slack.com. I tried variations using the -ERL_CFLAGS and -ERL_LDFLAGS options without any luck.

The only way I was able to get it to work was to manually modify a configuration file, first. Fortunately, the modification is pretty simple:

# you can use nano or whichever text editor you prefer here. I used vim.
vi ~/src/apache-couchdb-3.1.1/src/couch/rebar.config.script
# change line 111 of this file from:
# -L/usr/local/lib -lmozjs185 -lm
# to:
# -L$HOME/lib -lmozjs185 -lm
# save the file and exit the text editor

This line tells CouchDB to look for Spidermonkey where we installed it in the first step.

Now we can proceed to install CouchDB. You may want to put the following commands into a file called buildcouch2of2.sh:

cd $HOME/src/apache-couchdb-3.1.1
export LD_LIBRARY_PATH=$HOME/lib:$LD_LIBRARY_PATH
./configure
make
make release ERL_CFLAGS="-I $HOME/include/js -I $HOME/lib/erlang"
cp -r ./rel/couchdb $HOME/opt/

Run these commands. Congratulations! You've just built and installed CouchDB 3.1.1 and its dependencies. CouchDB now lives at ~/opt/couchdb.

In order to actually use couchdb, you'll need to create one or more admin users and complete some additional configuration steps. Admin users can be specified in ~/opt/couchdb/etc/local.ini - scroll to the last line and change it to admin = yourSecurePassword (don't forget to remove the semicolon prefixing this line, and you should actually use a secure password in place of 'yourSecurePassword' above).

You should set up a 'Proxy Port' application in Opalstack for couchdb. Set the port in the [chttpd] section of ~/opt/couchdb/etc/default.ini to the port assigned to this application.

You should now be able to start couchdb by executing the following command: ~/opt/couchdb/bin/couchdb. Assuming you want a single node setup, rather than a cluster, you can execute the following three commands to create the initial system databases. You'll need to have couch running in order to do this, so you may want to be in a tmux or screen session, and you should replace 'YOURPORT' with the port assigned to your Proxy Port application):

# you'll need to enter the password you assigned to your admin user after each of these commands
curl -u admin -X PUT http://127.0.0.1:YOURPORT/_users
curl -u admin -X PUT http://127.0.0.1:YOURPORT/_replicator
curl -u admin -X PUT http://127.0.0.1:YOURPORT/_global_changes

Now, assuming couch is running, and you have set up a site route pointing to the Proxy Port application, you should be able to visit yourcouchdomain.com/_utils in your web browser and interact with CouchDB's 'fauxton' web GUI. Log in to fauxton with the admin user you created earlier, and you're good to go!

Things to add:

  1. Instructions on running couch as a daemon and restarting it automatically if it crashes.

Useful links:

  1. https://docs.couchdb.org/en/stable/install/unix.html#installation-from-source
  2. https://docs.couchdb.org/en/stable/config/auth.html#config-admins
  3. https://docs.couchdb.org/en/stable/setup/single-node.html
  4. https://community.webfaction.com/questions/557/installing-couchdb

    kurt Thanks for sharing this! ❤️

    Also, we could install firefox 60.9.0, but it requires a newer version of gcc than Opalstack has installed, so we'll use spidermonkey 1.8.5.

    You can use a newer gcc by enabling it with scl. More info here: HOWTO use a newer version of gcc

      sean I'd like to install firefox 60 for access to more modern JS language features, but I'm stumped right now.

      I enabled devtoolset-9 following the instructions at the article you linked (scl enable devtoolset-9 bash), then executed the following commands:

      cd $HOME/src
      wget 'https://archive.mozilla.org/pub/firefox/releases/60.9.0esr/source/firefox-60.9.0esr.source.tar.xz'
      tar -xf firefox-60.9.0esr.source.tar.xz
      cd firefox-60.9.0/js/src
      ./configure --prefix=$HOME

      Here are the last few relevant log lines from ./configure --prefix=$HOME:

      checking the target C compiler version... 9.3.1
      checking the target C compiler works... yes
      checking for the target C++ compiler... not found
      DEBUG: _cxx: Trying /opt/rh/devtoolset-9/root/usr/bin/g++
      ERROR: Cannot find the target C++ compiler

      I've also tried following this set of instructions for building Firefox from source but am not able to clone from the source repo with bootstrap.py using mercurial or git.

      Would Opalstack be willing to install Firefox 60.9 on its servers? I think that would make it possible to simplify the couchdb installation tutorial, as well. If that's not an option, no worries. I'll keep hacking at it, and at least it is already working with Spidermonkey 1.8.5.

      Edit: I'm also trying to install via ./mach bootstrap, but that expects sudo. I'll see whether I can find a way around that, but I'm stymied at the moment.

      • sean replied to this.

        kurt I guess the devtoolset-9 collection doesn't have everything needed to build Firefox.

        You don't actually need a compiler to install Firefox, you can just download a Firefox binary and run it:

        mkdir ~/opt
        cd ~/opt
        wget https://download-installer.cdn.mozilla.net/pub/firefox/releases/84.0.1/linux-x86_64/en-US/firefox-84.0.1.tar.bz2
        tar jxf firefox-84.0.1.tar.bz2

        When that'd done Firefox will be installed in ~/opt/firefox:

        $ ~/opt/firefox/firefox --version
        Mozilla Firefox 84.0.1
        • kurt replied to this.

          sean Thanks! Unfortunately, I don't think this helps me.

          CouchDB requires mozjs185 (which I build in the tutorial), mozjs60 or mozjs68. While I can download the complete v60 and v68 binaries and run firefox, the binaries don't include Spidermonkey as a separate library.

          I believe Opalstack has mozjs17 installed sever-wide, but that's not an option for CouchDB 3.1.1.

          • sean replied to this.

            kurt ah, I see.

            The newest mozjs we have available is mozjs52. If you think that will help then let me know and I'll see if we can get that installed for you.

            • kurt replied to this.

              sean Thanks, Sean. Unfortunately, the only Spidermonkey versions supported by CouchDB 3.1.1 are 1.8.5, 60 and 68. I'm throwing in the towel on using a more recent version of Spidermonkey for now. I may swing back to it some other time.

              Mastodon