Introduction
Overleaf is an open-source online LaTeX editor. With the help of Overleaf, students and academics can work together on a single LaTeX document to produce high-quality output.
This article walks through installing Overleaf Community Edition on a Rcs Ubuntu 20.04 LTS server instance.
Prerequisites
- A fresh Rcs Ubuntu 20.04 LTS server instance with at least 2 CPU cores and 4GB of memory, suitable for about ten concurrent users. If you need to serve more users, add 1 CPU core and 1 GB of memory for every five more concurrent users. Assuming the server instance's IPv4 address is 203.0.113.100.
- A domain name example.com for accessing the Overleaf LaTeX editor site.
1. Setup DNS Records
If you are hosting example.com on Rcs, set up DNS records as follows to point example.com and www.example.com to the IPv4 address of your server instance (203.0.113.100) in the DNS tab of the Rcs control panel:
Entry #1
- Type: A
- Name: [blank]
- Data: 203.0.113.100
- TTL (seconds): 300
- Priority:
Entry #2
- Type: A
- Name: www
- Data: 203.0.113.100
- TTL (seconds): 300
Entry #3
- Type: MX
- Name: [blank]
- Data: example.com
- TTL (seconds): 300
- Priority: 10
Entry #4
- Type: NS
- Name: [blank]
- Data: ns1.vultr.com
- TTL (seconds): 300
Entry #5
- Type: NS
- Name: [blank]
- Data: ns2.vultr.com
- TTL (seconds): 300
If you are hosting example.com on other platforms, instructions on setting up DNS records may vary.
Learn more about managing DNS through Rcs in an article on Rcs DNS.
2. Harden the System
Use an SSH terminal to log in to the server instance as root, and then follow the instructions listed in this section to harden the system.
Determine if any swap file or swap partition exists in the system:
# swapon -s
If so, feel free to move on. If not, set up a swap file of 2GB to smooth the operation of the system:
# fallocate -l 2g /swap
# chmod 0600 /swap
# mkswap /swap
# swapon /swap
# echo '/swap none swap defaults 0 0' | tee -a /etc/fstab
# free -m
Change the preset password of root to a new, strong, and private password (Say it is r00tyHvM%2ka$8E3):
# echo 'root:r00tyHvM%2ka$8E3' | chpasswd && history -d -1
Create a normal user named overleaf with sudo privileges, and then set up a strong password for the sudo user. Say the password is sud04QeXbcx#6&Cw:
# useradd -ms /bin/bash overleaf
# echo 'overleaf:sud04QeXbcx#6&Cw' | chpasswd && history -d -1
# echo 'overleaf ALL=(ALL) NOPASSWD: ALL' | tee -a /etc/sudoers.d/designated
# chmod 0440 /etc/sudoers.d/designated
Setup UFW firewall rules, allowing only traffic on SSH (22), HTTP (80), and HTTPS (443) ports:
# ufw default deny
# ufw allow 22
# ufw allow 80
# ufw allow 443
# ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y:key_enter:
# ufw status verbose
Update the system and then reboot the machine:
# apt update
# apt upgrade -y
# apt autoremove -y
# shutdown -r now
After the server instance gets up and running again, log in as the sudo user overleaf to move on.
3. Install Docker Engine
Uninstall any earlier versions of Docker in the system, if they exist:
$ sudo apt remove docker docker-engine docker.io containerd runc
It's OK to see the system prompts E: Unable to locate package docker-engine.
Install dependencies for setting up the Docker Engine Advanced Packaging Tool (APT) repository:
$ sudo apt update
$ sudo apt install ca-certificates curl gnupg lsb-release -y
Get the official Docker GPG key:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Setup the APT repository for the stable release of Docker Engine:
$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Install Docker Engine and containerd:
$ sudo apt update
$ sudo apt install docker-ce docker-ce-cli containerd.io -y
To control Docker Engine as a non-root user, add the current normal user overleaf to the docker group:
$ sudo usermod -aG docker $USER
$ newgrp docker
Configure Docker Engine to enable automatic log rotation, restricting disk space usage of the Docker Engine log files:
$ sudo nano /etc/docker/daemon.json
Populate the file with:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}
Press Ctrl+O, Enter, and Ctrl+X to save the file and quit.
Start the Docker service and configure it to start on boot:
$ sudo systemctl start docker.service
$ sudo systemctl enable docker.service
Start the containerd service and configure it to start on boot, too:
$ sudo systemctl start containerd.service
$ sudo systemctl enable containerd.service
Verify the installation of Docker Engine:
$ docker --version
Docker version 20.10.12, build e91ed57
To test the functionality of Docker, Use Docker to run a "hello world" image:
$ docker run hello-world
...
Hello from Docker!
4. Install Docker Compose V1.x
As required by Overleaf, install the latest stable release of Docker Compose V1.x as follows:
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod a+x /usr/local/bin/docker-compose
$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
Optionally, install Docker Compose command completion for Bash:
$ sudo curl -L https://raw.githubusercontent.com/docker/compose/1.29.2/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose
Confirm the installation of Docker Compose v1.x:
$ docker-compose --version
docker-compose version 1.29.2, build 5becea4c
Note: The above instructions are only for installing Docker Compose 1.29.2. Be sure to find out if a newer version of Docker Compose is available on the official Docker Compose installation page.
5. Install and Configure Overleaf
The officially recommended tool for installing Overleaf is the Overleaf Toolkit which consists of a series of scripts wrapping around the Docker Compose program.
Use git to download Overleaf Toolkit:
$ cd /opt
$ sudo apt install git -y
$ sudo git clone https://github.com/overleaf/toolkit.git ./overleaf
$ sudo chown -R overleaf:overleaf /opt/overleaf
Initialize Overleaf local environment with the --tls flag to enable Transport Layer Security (TLS):
$ cd /opt/overleaf
$ bin/init --tls
Running the above script generates a self-signed TLS certificate in /opt/overleaf/config/nginx/certs/overleaf_certificate.pem and the paired private key in /opt/overleaf/config/nginx/certs/overleaf_key.pem. Replace them with your own ones if necessary, but be sure to keep the same file names and the same permissions on them.
Set environment variables for running Overleaf Community Edition behind the Nginx TLS proxy:
$ nano /opt/overleaf/config/variables.env
Find the two lines listed below:
# SHARELATEX_BEHIND_PROXY=true
# SHARELATEX_SECURE_COOKIE=true
Uncomment them:
SHARELATEX_BEHIND_PROXY=true
SHARELATEX_SECURE_COOKIE=true
Optionally, edit lines listed below to customize the interface of your Overleaf site:
SHARELATEX_APP_NAME=Our Overleaf Instance
# SHARELATEX_SITE_URL=http://overleaf.example.com
# SHARELATEX_NAV_TITLE=Our Overleaf Instance
# SHARELATEX_HEADER_IMAGE_URL=http://somewhere.com/mylogo.png
# SHARELATEX_ADMIN_EMAIL=support@example.com
# SHARELATEX_LEFT_FOOTER=[{"text":"Powered by Overleaf © 2021", "url": "https://www.overleaf.com"}, {"text": "Contact your support team", "url": "mailto:support@example.com"} ]
# SHARELATEX_RIGHT_FOOTER=[{"text":"Hello I am on the Right"}]
Example modifications:
SHARELATEX_APP_NAME=Overleaf
SHARELATEX_SITE_URL=https://www.example.com
SHARELATEX_NAV_TITLE=EXAMPLE.COM
SHARELATEX_HEADER_IMAGE_URL=https://www.example.com/mylogo.png
SHARELATEX_ADMIN_EMAIL=admin@example.com
SHARELATEX_LEFT_FOOTER=[{"text":"Powered by Overleaf", "url": "https://www.overleaf.com"}, {"text": "Contact us", "url": "mailto:admin@example.com"} ]
SHARELATEX_RIGHT_FOOTER=[{"text":"©2022 EXAMPLE.COM. All rights reserved."}]
Press Ctrl+O, Enter, and Ctrl+X to save the file and quit.
Note: This article omits instructions on how to update SMTP-related settings stored in the same file, because Rcs blocks the SMTP port 25 on each server instance by default according to its anti-spam policy. Contact Rcs customer service to remove the restriction if you do need to enable SMTP email sending on your server instance.
Edit Nginx-related settings in another Overleaf configuration file:
$ nano /opt/overleaf/config/overleaf.rc
Find the lines listed below:
NGINX_ENABLED=false
NGINX_HTTP_LISTEN_IP=127.0.1.1
NGINX_TLS_LISTEN_IP=127.0.1.1
Replace them with:
NGINX_ENABLED=true
NGINX_HTTP_LISTEN_IP=203.0.113.100
NGINX_TLS_LISTEN_IP=203.0.113.100
Press Ctrl+O, Enter, and Ctrl+X to save the file and quit.
Run all the Overleaf Docker services in background:
$ cd /opt/overleaf
$ bin/up -d
...
Creating mongo ... done
Creating redis ... done
Creating sharelatex ... done
Creating nginx ... done
After all Docker services are up and running, point your favorite web browser to www.example.com/lauchpad to register the first administrator account.
When using a self-signed certificate, your web browser, such as Chrome, will warn you that your connection is not private. Feel free to ignore the security alert. Click the Advanced button, and then the Proceed to www.example.com (unsafe) link to visit the Overleaf registration page.
On the Overleaf registration page, input your email address and password, and then click the Register button to finish the registration of the first administrator. Click the Log in here link to go to the Log In page, and then use the administrator's credentials to log in.
6. Update TeX Live to a Complete Installation
By default, the Overleaf Docker image only includes a minimal installation of TeX Live to save bandwidth. Follow the instructions in this section to update TeX Live to a complete installation.
While Overleaf is running, use the commands below to start a shell inside the Overleaf container:
$ cd /opt/overleaf
$ bin/shell
The prompt will turn into something that looks like root@4945b4907b6f:/#.
Update the tlmgr program:
root@4945b4907b6f:/# tlmgr update --self
Optionally, find the URL of the nearest Comprehensive TEX Archive Network (CTAN) repository location from the https://ctan.org/mirrors site, such as https://mirrors.mit.edu/CTAN/, and then change the default repository location as follows:
root@4945b4907b6f:/# tlmgr option repository https://mirrors.mit.edu/CTAN/systems/texlive/tlnet/
Update TeX Live to a complete installation in the background, combining with the nohup command to prevent update failure caused by any accidental SSH disconnection:
root@4945b4907b6f:/# nohup tlmgr install scheme-full &
Downloading and installing all the TeX Live packages (more than 4,000 packages) may take a while. Use the command listed below to check for the progress at any time:
root@4945b4907b6f:/# tail nohup.out
Until you see the output ends at:
...
tlmgr: package log updated: /usr/local/texlive/2021/texmf-var/web2c/tlmgr.log
tlmgr: command log updated: /usr/local/texlive/2021/texmf-var/web2c/tlmgr-commands.log
Having all the TeX Live packages in place, update them to the latest versions:
root@4945b4907b6f:/# tlmgr update --self --all
Exit the shell inside the Overleaf container:
root@4945b4907b6f:/# exit
To make your changes to the Overleaf container persistent, use the command listed below to save the changes:
$ docker commit sharelatex sharelatex/sharelatex:with-texlive-full
sha256:d8191965e06c1e7f71d8fd596523875e1ab0e29d5062f088893728e29c62b87b
Set up an overriding Docker Compose configuration file to reflect the changes:
$ nano /opt/overleaf/lib/docker-compose.override.yml
Populate the file with:
---
version: '2.2'
services:
sharelatex:
image: sharelatex/sharelatex:with-texlive-full
Press Ctrl+O, Enter, and Ctrl+X to save the file and quit.
Note:
- The version number, which is 2.2 in this case, must be the same as the version number in other Docker Compose configuration files, such as /opt/overleaf/lib/docker-compose.base.yml.
- Do not use tabs for indents when dealing a .yml file. Use 2 or 4 spaces for 1 indent.
Finally, stop the running Docker services, delete the former ShareLaTeX container, and then restart the Overleaf Docker services:
$ cd /opt/overleaf
$ bin/stop && bin/docker-compose rm -f sharelatex && bin/up -d
Stopping nginx ... done
Stopping sharelatex ... done
Stopping mongo ... done
Stopping redis ... done
Going to remove sharelatex
Removing sharelatex ... done
Starting redis ... done
Starting mongo ... done
Creating sharelatex ... done
Recreating nginx ... done
Next Steps
Depending on the specific languages you plan to use, you must select the proper LaTeX compiling engine and fonts when typesetting your documents with Overleaf. To learn more about configuring Overleaf for typesetting documents in the languages you prefer, visit the Overleaf Documentation page.