Author: Allen J.
Last Updated: Tue, Mar 1, 2022Cachet is the free and open source status page for your API, service or company. Built with all of the features that you'd expect from a status page, Cachet comes with a powerful API, a metric system, multiple user support, two factor authentication for added security and is easy to get setup. A powerful, self-hosted alternative to StatusPage.io and Status.io. This article explains how to set up Cachet on a Ubuntu 20.04 x64 server using Vultr's one-click Docker Application and setting up your status page as a subdomain with CaddyServer so that you instantly have SSL enabled.
Login as root and run the following commands.
$ apt-get update -y
$ apt-get install git
$ docker network create caddy
Change into the /home
directory.
$ cd /home
Clone the the CachetHQ repository.
$ git clone https://github.com/cachethq/Docker.git cachet-docker
Change into the /home/cachet-docker
directory
$ cd cachet-docker
Open the docker-compose.yml file.
$ nano docker-compose.yml
Look for the following line:
cachet:
Add container_name: cachet
below that line, so it looks like this:
cachet:
container_name: cachet
In the environment:
section, add - APP_URL=<https://subdomain.example.com>
to the end, after - DEBUG=false
. When finished, it will look like this:
environment:
- DB_DRIVER=pgsql
- DB_HOST=postgres
- DB_PORT=5432
- DB_DATABASE=postgres
- DB_USERNAME=postgres
- DB_PASSWORD=postgres
- DB_PREFIX=chq_
- APP_KEY=${APP_KEY:-null}
- APP_LOG=errorlog
- APP_ENV=${APP_ENV:-production}
- APP_DEBUG=false
- DEBUG=false
- APP_URL=<https://subdomain.example.com>
Add the following section to the end of the file.
networks:
default:
external:
name: caddy
Save and exit the file. The completed file should look like this:
version: "3"
services:
postgres:
image: postgres:12-alpine
volumes:
- /var/lib/postgresql/data
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
restart: always
cachet:
container_name: cachet
build:
context: .
args:
- cachet_ver=2.4
ports:
- 80:8000
links:
- postgres:postgres
environment:
- DB_DRIVER=pgsql
- DB_HOST=postgres
- DB_PORT=5432
- DB_DATABASE=postgres
- DB_USERNAME=postgres
- DB_PASSWORD=postgres
- DB_PREFIX=chq_
- APP_KEY=${APP_KEY:-null}
- APP_LOG=errorlog
- APP_ENV=${APP_ENV:-production}
- APP_DEBUG=false
- DEBUG=false
- APP_URL=<https://subdomain.example.com>
depends_on:
- postgres
restart: on-failure
networks:
default:
external:
name: caddy
Open the conf/nginx-site.conf
file:
$ nano conf/nginx-site.conf
Add fastcgi_param HTTPS on;
after the fastcgi_keep_conn on;
line, so it looks like this:
fastcgi_keep_conn on;
fastcgi_param HTTPS on;
Save the file.
Run docker-compose build
to build the images.
$ docker-compose build
Run docker-compose up
to start the containers.
$ docker-compose up
Locate the ERROR line that displays the following error and take note of the APP_KEY
given to you.
cachet_1 | ERROR: Please set the 'APP_KEY=base64:1b3Ni9TaOHdbliYWKPM+bqv7kSJ/BZx7PzAde1yPm+k=' environment variable at runtime or in docker-compose.yml and re-launch
Open the docker-compose.yml
file.
$ nano docker-compose.yml
Locate the APP_KEY
variable, which should look like this:
- APP_KEY=${APP_KEY:-null}
Replace the APP_KEY
variable with what was given to you in the ERROR: line after running docker-compose up
so it looks like below and save the file:
- APP_KEY=base64:1b3Ni9TaOHdbliYWKPM+bqv7kSJ/BZx7PzAde1yPm+k=
Run docker-compose build
and docker-compose up -d
again.
Change into the /home
directory.
$ cd /home
Create a new directory called caddy
.
$ mkdir caddy
Change into the /home/caddy
directory.
$ cd caddy
Create a new Caddyfile.
$ nano Caddyfile
Paste the following contents, replacing the domain with your domain you configured with DNS and save that file:
status.example.com {
reverse_proxy cachet:8000
}
Create a docker-compose.yml file.
$ nano docker-compose.yml
Paste the following content:
version: '3.1'
services:
caddy:
ports:
- 443:443
image: caddy/caddy
volumes:
- ./caddy/data:/data
- ./Caddyfile:/etc/caddy/Caddyfile
networks:
default:
external:
name: caddy
Run the following command to initalize Caddy to get the certificates:
$ docker-compose up -d
In your web browser, navigate to https://status.example.com
to start configuring your new Cachet status page.
Run the following command to open the ssh configuration and change your SSH port to a non-standard port number:
$ nano /etc/ssh/sshd_config
Locate the following line that reads:
#Port 22
Uncomment out the line by removing the # symbol and change the port so it looks like this:
Port 2222
Save the file, update your firewall to accept the new port, and restart the firewall:
$ ufw allow 2222/tcp
$ service ssh restart