Etherpad Lite on Ubuntu 10.04 with Nginx reverse proxy

Etherpad Lite on Ubuntu 10.04 with Nginx reverse proxy

Etherpad Lite is an opensource web-based word processor that allows people to work together on a document in real time. When multiple people edit the same document simultaneously, changes by any individual are instantly reflected on everyone’s screen. The result is a new way to collaborate on text documents, which is particularly useful for meeting notes, drafting sessions, education, team programming, and more. People currently viewing an active pad appear in a sidebar, and each person is assigned a unique background color to track individual contributions. You can type, undo, copy, and paste without interfering with other people‚Äôs simultaneous edits to the pad. Backup copies of all saved revisions can be restored at any time.

I was using a public Etherpad Lite site with a large group of users when..the site simply kept going down every few minutes. So I decided to roll out my own on a VPS.

This tutorial will walk you through the steps of installing Etherpad Lite on a minimal install instance of Ubuntu 10.04 LTS, which will be accessed via http://etherpad.myserver.net The steps are pulled together from the official documentation.

Step 1: Install pre-requisites

apt-get install build-essential python libssl-dev git-core libsqlite3-dev gzip curl

Step 2: Setup etherpad user

sudo adduser etherpad
su etherpad

Step 3: Install nodeJS

mkdir ~/local
cd ~/local
wget http://nodejs.org/dist/node-v0.4.10.tar.gz
tar -zxvf node-v0.4.10.tar.gz
cd node-v0.4.10/
./configure –prefix=$HOME/local/node
make
make install
echo ‘export PATH=$HOME/local/node/bin:$PATH’ >> ~/.profile
echo ‘export NODE_PATH=$HOME/local/node:$HOME/local/node/lib/node_modules’ >> ~/.profile
source ~/.profile

Step 4: Install NPM

curl http://npmjs.org/install.sh | sh
# You will be prompted to type yes
# No instructions said to change directory but it seems cleaner.
cd ../

Step 5: Install and run Etherpad Lite

git clone ‘git://github.com/Pita/etherpad-lite.git’
etherpad-lite/bin/installDeps.sh
etherpad-lite/bin/run.sh

Step 6: Setup Etherpad Lit as a service

sudo mkdir /var/log/etherpad-lite
sudo chown etherpad /var/log/etherpad-lite
sudo chown -R etherpad /var/log/etherpad-lite
sudo vi /etc/init.d/etherpad-lite
sudo chmod 755 /etc/init.d/etherpad-lite
sudo nano /etc/init.d/etherpad-lite

And now copy-and-paste the following into the contents of /etc/init.d/etherpad-lite

### BEGIN INIT INFO
# Provides: etherpad-lite
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts etherpad lite
# Description: starts etherpad lite using start-stop-daemon
### END INIT INFO

PATH=”/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/node/bin:/home/etherpad/local/node/bin”
LOGFILE=”/var/log/etherpad-lite/etherpad-lite.log”
EPLITE_DIR=”/home/etherpad/local/etherpad-lite”
EPLITE_BIN=”bin/safeRun.sh”
USER=”etherpad”
GROUP=”etherpad”
DESC=”Etherpad Lite”
NAME=”etherpad-lite”

set -e

. /lib/lsb/init-functions

start() {
echo “Starting $DESC… ”

start-stop-daemon –start –chuid “$USER:$GROUP” –background –make-pidfile –pidfile /var/run/$NAME.pid –exec $EPLITE_DIR/$EPLITE_BIN — $LOGFILE || true
echo “done”
}

#We need this function to ensure the whole process tree will be killed
killtree() {
local _pid=$1
local _sig=${2-TERM}
for _child in $(ps -o pid –no-headers –ppid ${_pid}); do
killtree ${_child} ${_sig}
done
kill -${_sig} ${_pid}
}

stop() {
echo “Stopping $DESC… ”
while test -d /proc/$(cat /var/run/$NAME.pid); do
killtree $(cat /var/run/$NAME.pid) 15
sleep 0.5
done
rm /var/run/$NAME.pid
echo “done”
}

status() {
status_of_proc -p /var/run/$NAME.pid “” “etherpad-lite” && exit 0 || exit $?
}

case “$1” in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
*)
echo “Usage: $NAME {start|stop|restart|status}” >&2
exit 1
;;
esac

exit 0

Now launch Etherpad Lite

sudo /etc/init.d/etherpad-lite start

Woohoo now we can see Etherpad Lite running on http://etherpad.myserver.net:9001
But that’s rather difficult to remember – how can we get rid of port 9001 at the end?
The solution is a simple reverse-proxy using Nginx!

Step 7: Install and setup Nginx

sudo apt-get install nginx
sudo nano /etc/nginx/sites-enabled/etherpad.myserver.net

Copy-and-paste the following into /etc/nginx/sites-enabled/etherpad.myserver.net

server {
listen 80;
server_name etherpad.myserver.net;

access_log /var/log/nginx/access.log;

location / {
proxy_pass http://localhost:9001;
# include /etc/nginx/proxy.conf;
proxy_buffering off;
}
}

Step 8: Launch Nginx

/etc/init.d/nginx restart

Now your Etherpad Lite instance can be accessed directly from http://etherpad.myserver.net!
Enjoy!