Previous Page

nihilist - 00 / 00 / 00

ShareLaTeX / Overleaf

Today we're going to setup an Open-source real-time collaborative LaTeX editor.

Initial Setup

Setup Docker to get started

root@home:~# apt install -y

Once it's installed, you can look for sharelatex's containers:

root@docker0:~# docker search sharelatex

root@docker0:~/sharelatex# docker search sharelatex
NAME                                         DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
sharelatex/sharelatex                        The official ShareLaTeX Community Edition do…   67
tiagoboldt/sharelatex-docker                                                                 21                                      [OK]
xuio/sharelatex-docker-image-full            Sharelatex docker image with scheme-full        4                                       [OK]
sharelatex/sharelatex-base                   ShareLaTeX base-image                           3
dennis1f/sharelatex-texlive2018              sharelatex with texlive 2018                    2                                       [OK]
braindoctor/sharelatex                       Official Sharelatex image, but with full tex…   2                                       [OK]
jrandall/sharelatex                                                                          1                                       [OK]
rigon/sharelatex-full                        ShareLatex with all Latex packages installed…   1                                       [OK]
flodointhecloud/sharelatex-texlive2019        ShareLaTeX docker image with full TeX Live …   1
jonasbareiss/sharelatex                                                                      0
shimmyjimi/sharelatex                        Build of sharelatex / overleaf comunity to g…   0
sharelatex/copybara                          Our build of google/copybara                    0
jperon/sharelatex-music                      ShareLaTeX with Gregorio and LilyPond.          0                                       [OK]
dpantele/sharelatex                          Automated build of custom sharelatex image      0                                       [OK]
sharelatex/acceptance-test-runner                                                            0
yousiki/sharelatex                                                                           0
iiet/sharelatex-docker-image                 Sharelatex custom build                         0                                       [OK]
sharelatex/acceptance-test-runner-postgres                                                   0
sharelatex/node-aspell                                                                       0
jonathanverner/sharelatex                    ShareLaTeX Community Edition (with tweaks)      0
sleyai/sharelatex                                                                            0
marijnhollander/sharelatex                   Sharelatex image with tlmgr scheme-full, Pyg…   0
459below/sharelatex                          Standard Sharelatex container to include the…   0                                       [OK]
mwohlert/sharelatex-full                0
thielepaul/sharelatex-full                                                                   0

You can pull sharelatex and mongodb, setting it all up manually, or you can just have the official docker-compose image:

root@docker0:~# ls -lsh
total 16K
4.0K drwxr-xr-x  2 root root 4.0K Apr 18 19:16 codimd
4.0K drwxr-xr-x 11 root root 4.0K Apr 18 08:03 dillinger
4.0K drwxr-xr-x  7 root root 4.0K Apr 18 08:03 kutt
4.0K drwxr-xr-x  2 root root 4.0K Apr 18 08:56 neko
root@docker0:~# mkdir sharelatex
root@docker0:~# cd sharelatex/
root@docker0:~/sharelatex# wget
--2021-04-18 20:28:44--
Resolving (,,, ...
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5639 (5.5K) [text/plain]
Saving to: ‘docker-compose.yml’

docker-compose.yml                     100%[============================================================================>]   5.51K  --.-KB/s    in 0.001s

2021-04-18 20:28:44 (4.02 MB/s) - ‘docker-compose.yml’ saved [5639/5639]

root@docker0:~/sharelatex# vim docker-compose.yml

Yes this docker-compose.yml is relatively big compared to what we previously did, but that's life. For now we're going to test it locally, so we won't bother with the domain names and reverse proxy:

version: '2.2'
        restart: always
        image: sharelatex/sharelatex
        container_name: sharelatex
                condition: service_healthy
                condition: service_started
            - 8090:80
            - mongo
            - redis
            - ~/sharelatex_data:/var/lib/sharelatex


            SHARELATEX_APP_NAME: Overleaf Community Edition

            SHARELATEX_MONGO_URL: mongodb://mongo/sharelatex

            # Same property, unfortunately with different names in
            # different locations
            SHARELATEX_REDIS_HOST: redis
            REDIS_HOST: redis

            ENABLED_LINKED_FILE_TYPES: 'url,project_file'

            # Enables Thumbnail generation using ImageMagick
            ENABLE_CONVERSIONS: 'true'

            # Disables email confirmation requirement

            # temporary fix for LuaLaTex compiles
            # see
            TEXMFVAR: /var/lib/sharelatex/tmp/texmf-var

            ## Set for SSL via nginx-proxy

            # SHARELATEX_SITE_URL:
            # SHARELATEX_NAV_TITLE: Our ShareLaTeX Instance

            # SHARELATEX_LEFT_FOOTER: '[{"text": "Powered by ShareLaTeX 2016"},{"text": "Another page I want to link to can be found here"} ]'
            # SHARELATEX_RIGHT_FOOTER: '[{"text": "Hello I am on the Right"} ]'



            # SHARELATEX_CUSTOM_EMAIL_FOOTER: "This system is run by department x"

        restart: always
        image: mongo:4.0
        container_name: mongo
            - 27017
            - ~/mongo_data:/data/db
            test: echo 'db.stats().ok' | mongo localhost:27017/test --quiet
            interval: 10s
            timeout: 10s
            retries: 5

        restart: always
        image: redis:5
        container_name: redis
            - 6379
            - ~/redis_data:/data


The only thing in here that i changed is the port (from 80:80 to 8090:80) because my port 80 is used by another container. Once you're done editing it, hit :wq to save and quit out of vim, then use docker-compose to build the container from the yml file:

root@docker0:~/sharelatex# ls -lash
total 12K
4.0K drwxr-xr-x  2 root root 4.0K Apr 18 20:34 .
4.0K drwx------ 12 root root 4.0K Apr 18 20:34 ..
4.0K -rw-r--r--  1 root root 3.0K Apr 18 20:34 docker-compose.yml

root@docker0:~/sharelatex# docker-compose up -d
Creating network "sharelatex_default" with the default driver
Pulling mongo (mongo:4.0)...
4.0: Pulling from library/mongo


81cf86179504: Pull complete
52fbbc31d2bb: Pull complete
Digest: sha256:2b7dd04de6915c427c5ed116d602eb02329466dcf76c4f506284685ba995bcc3
Status: Downloaded newer image for sharelatex/sharelatex:latest
Creating redis ... done
Creating mongo ... done
Creating sharelatex ... done

Once it's done, you can check the containers like so:

root@docker0:~/sharelatex# docker container ls
CONTAINER ID        IMAGE                   COMMAND                  CREATED              STATUS                        PORTS                                                          NAMES
831a57e1a4b6        sharelatex/sharelatex   "/sbin/my_init"          About a minute ago   Up About a minute   >80/tcp                                           sharelatex
d9f12a3b40f3        mongo:4.0               "docker-entrypoint.s…"   About a minute ago   Up About a minute (healthy)   27017/tcp                                                      mongo
73817b58274a        redis:5                 "docker-entrypoint.s…"   About a minute ago   Up About a minute             6379/tcp 

Looks good! let's check it out from our browser, and to setup our first admin user account we need to go to

Once the admin account is created, we login and go take a look at the admin panel:

Above all we can go to the admin panel to register new users, or

And that's it! We have been able to create our first LaTeX document on ShareLaTeX, we could locally share the document, but we would of course prefer to share it publicly. To do so we're going to setup a NGINX reverse proxy to make sure we have HTTPS and a subdomain for this service:

Reverse NGINX Proxy

We're going to setup the reverse nginx proxy on my main debian node (

[ ] [ /dev/pts/6 ] [Github/blog/servers]
→ ssh root@
root@'s password:
Linux home 4.19.0-16-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Apr 18 20:19:25 2021 from

root@home:/var/www/ vim /etc/nginx/sites-available/

upstream latbackend {

server {
        listen 80;
        listen [::]:80;
        return 301 https://$server_name$request_uri;

server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;

        ssl_certificate /root/;
        ssl_trusted_certificate /root/;
        ssl_certificate_key /root/;

        ssl_protocols TLSv1.3 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:10m;
        ssl_session_timeout 10m;
        ssl_session_tickets off;
        ssl_ecdh_curve auto;
        ssl_stapling on;
        ssl_stapling_verify on;
        resolver valid=300s;
        resolver_timeout 10s;

        add_header X-XSS-Protection "1; mode=block"; #Cross-site scripting
        add_header X-Frame-Options "SAMEORIGIN" always; #clickjacking
        add_header X-Content-Type-Options nosniff; #MIME-type sniffing
        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";

        location / {
                proxy_pass http://latbackend;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "Upgrade";

:wq to save and quit out of vim, then enable the website:

root@home:/var/www/ ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/
root@home:/var/www/ nginx -t
nginx: [emerg] BIO_new_file("/root/") failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/root/','r') error:2006D080:BIO routines:BIO_new_file:no such file)
nginx: configuration file /etc/nginx/nginx.conf test failed

Here you see nginx fail. That's because we need to get the TLS certificates, and we get them from LetsEncrypt thanks to

root@home:/var/www/ systemctl stop nginx
root@home:/var/www/ --issue --standalone -d -k 4096
root@home:/var/www/ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

After getting the TLS certificates, nginx is now fine with our config, so start it again and see the result:

root@home:/var/www/ systemctl start nginx

Here you can see that the website is now accessible from a public IP and subdomain, which is also securised by LetsEncrypt Certificates. Now let's test sharing the link with guests (make sure you create their accoutns first):

And that's it! we have been able to send a link to a pre-registered user to collaborate on LaTeX documents.


Until there is Nothing left.

About nihilist

Donate XMR: 8AUYjhQeG3D5aodJDtqG499N5jXXM71gYKD8LgSsFB9BUV1o7muLv3DXHoydRTK4SZaaUBq4EAUqpZHLrX2VZLH71Jrd9k8

Contact: (PGP)