Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
sharelatex (non-docker) installation on a ubuntu 16.04 server

Installing ShareLaTex on Ubuntu 16.04

Use this as-is without any warranty, and don't bug ShareLatex project members if there are problems with my instructions. They officialy support docker installation only.

This gist summarize the actions I did to setup a pure ShareLaTex community edition on a bare linux ubuntu 16.04 server (no docker). I intentionnaly tried to stick to distribution practice for running daemons (via runit, and not via a custom my_init + setuser wrapper).

I basically took ShareLaTeX receipt to build their docker and adapted it.

Install

After a clean ubuntu 16.04 setup, in a root shell:

Clone install files

git clone https://github.com/sharelatex/sharelatex-docker-image.git
cd sharelatex-docker-image

install package dependencies

export baseDir=.
apt-get update
curl -sL https://deb.nodesource.com/setup | sudo bash - # will point to nodejs 0.10.48
# better check the content of the previous url, before doing a 'sudo bash -'
apt-get install nodejs=0.10.48-1nodesource1~xenial1 # install version from nodesource repo
apt-mark hold nodejs # and don't update it with ubuntu's version
apt-get install -y build-essential wget unzip time imagemagick optipng strace nginx git python zlib1g-dev libpcre3-dev aspell aspell-en aspell-af aspell-am aspell-ar aspell-ar-large aspell-bg aspell-bn aspell-br aspell-ca aspell-cs aspell-cy aspell-da aspell-de aspell-de-alt aspell-el aspell-eo aspell-es aspell-et aspell-eu-es aspell-fa aspell-fo aspell-fr aspell-ga aspell-gl-minimos aspell-gu aspell-he aspell-hi aspell-hr aspell-hsb aspell-hu aspell-hy aspell-id aspell-is aspell-it aspell-kk aspell-kn aspell-ku aspell-lt aspell-lv aspell-ml aspell-mr aspell-nl aspell-no aspell-nr aspell-ns aspell-or aspell-pa aspell-pl aspell-pt-br aspell-ro aspell-ru aspell-sk aspell-sl aspell-st aspell-sv aspell-ta aspell-te aspell-tl aspell-tn aspell-ts aspell-uk aspell-uz aspell-xh aspell-zu
apt-get install runit sqlite3 mongodb-server redis-server # mongodb 2.6 seems to do fine with sharelatex
service nginx stop # will be handled via runit after
systemctl disable nginx
cp -r ${baseDir}/logrotate/sharelatex /etc/logrotate.d/sharelatex

install PDF viewer

pushd /opt
wget https://s3.amazonaws.com/sharelatex-random-files/qpdf-6.0.0.tar.gz && tar xzf qpdf-6.0.0.tar.gz
pushd /opt/qpdf-6.0.0
./configure && make && make install && ldconfig
popd; popd

Install TexLive

wget http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz
mkdir /install-tl-unx
tar -xvf install-tl-unx.tar.gz -C /install-tl-unx --strip-components=1

echo "selected_scheme scheme-basic" >> /install-tl-unx/texlive.profile;
/install-tl-unx/install-tl -profile /install-tl-unx/texlive.profile

rm -r /install-tl-unx
rm install-tl-unx.tar.gz

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/texlive/2016/bin/x86_64-linux/
tlmgr install latexmk
tlmgr install texcount

After that you will notice a lot of TexLive packages are missing when compiling projects, you can run tlmgr install scheme-full if you have enough time/space (server will get ~5GB)

Or manually install the required packages. A list of packages I use that should be enough for 90% of the case I guess is:

tlmgr install cyrillic collection-langcyrillic changepage fontenc fontspec libertine listings lmodern xcolor colortbl listings xtab minted wallpaper titlesec fancyhdr pgfpages geometry polyglossia extreport extsizes luaotfload luatexbase ctablestack fvextra fancyvrb upquote lineno float ifplatform xstring framed beamer everyshu everyshi ms mdframed avant helvetic beamerposter typ1cm type1cm fp euler captions caption textpos isodate substr xltxtra microtype

Install grunt globally

npm install -g grunt-cli
ln -s /usr/bin/nodejs /usr/bin/node

Install bcrpyt (problem with native module compilation)

npm install bcrypt

Deploy ShareLateX settings

mkdir /etc/sharelatex
cp ${baseDir}/settings.coffee /etc/sharelatex/settings.coffee
export SHARELATEX_CONFIG=/etc/sharelatex/settings.coffee

The configuration is referencing hostname dockerhost. In order to modify less files, we just add in /etc/hosts the following:

echo -e '127.0.0.1\tdockerhost' >> /etc/hosts

Set up ShareLaTex user and home directory

adduser --system --group --home /var/www/sharelatex --no-create-home sharelatex
mkdir -p /var/lib/sharelatex
chown www-data:www-data /var/lib/sharelatex
mkdir -p /var/log/sharelatex
chown www-data:www-data /var/log/sharelatex
mkdir -p /var/lib/sharelatex/data/template_files
chown www-data:www-data /var/lib/sharelatex/data/template_files
# my addition for future error with lualatex trying to write access $HOME
chown www-data:www-data /var/www 

Install ShareLaTeX

git clone https://github.com/sharelatex/sharelatex.git /var/www/sharelatex #random_change
cp ${baseDir}/services.js /var/www/sharelatex/config/services.js
cp ${baseDir}/package.json /var/www/package.json
cp ${baseDir}/git-revision.js /var/www/git-revision.js
pushd /var/www
npm install
popd
pushd /var/www/sharelatex
npm install
grunt install # that will takes some minutes to finish (error here with bcrypt compilation doesn't seem like a blocker)
popd

pushd /var/www
node git-revision > revisions.txt
popd

# Minify js assets
pushd /var/www/sharelatex/web
grunt compile:minify
popd

pushd /var/www/sharelatex/clsi
grunt compile:bin
popd
popd

Setup runit service manager

find ${baseDir}/runit -name run -exec sed -i 's#/sbin/setuser#chpst -u#' {} \;
cp -r ${baseDir}/runit/*            /etc/service

Here we need to customize the run script of clsi service (the one that handle latex compilation processes) Update file /etc/service/clsi-sharelatex/run accordingly

#!/bin/bash
export SHARELATEX_CONFIG=/etc/sharelatex/settings.coffee
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/texlive/2016/bin/x86_64-linux/ # add that line

exec /sbin/setuser www-data /usr/bin/node /var/www/sharelatex/clsi/app.js >> /var/log/sharelatex/clsi.log 2>&1

And customize the siteUrl via environment variable (other option is to edit /etc/sharelatex/settings.coffee)

via run file /etc/service/web-sharelatex/run

#!/bin/bash
export SHARELATEX_CONFIG=/etc/sharelatex/settings.coffee
export SHARELATEX_SITE_URL="http://texserver.corp" # add that line

exec chpst -u www-data /usr/bin/node /var/www/sharelatex/web/app.js >> /var/log/sharelatex/web.log 2>&1

Configure nginx reverse-proxy

rm /etc/nginx/sites-enabled/default
cp ${baseDir}/nginx/nginx.conf /etc/nginx/nginx.conf
cp ${baseDir}/nginx/sharelatex.conf /etc/nginx/sites-enabled/sharelatex.conf

Finish environment setup

# my addition (we won't use their /sbin/my_init wrapper so exec manually)
for f in init_scripts/*.sh; do
  sh $f
done

Add environment variable globally when running from a shell:

cat << EOF >>> /etc/bash.bashrc
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/texlive/2016/bin/x86_64-linux/
export SHARELATEX_CONFIG=/etc/sharelatex/settings.coffee
EOF

Final touch

service runit restart # give ~20 seconds for the whole site to be up (while everything is not up, you'll get 502 gateway error)

And create an admin user:

cd /var/www/sharelatex
grunt user:create-admin --email foo@bar.com

Backup

There are 3 things we want to look at for backing up data:

  • Mongodb : mongodump / mongorestore
  • Redis (not critical though, volatile info there)
  • Sharelatex user data files : rsync what is in /var/lib/sharelatex/data/

TODO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.