Cachet: Open Source Status Page

Companies that operate in the cloud need status pages to keep users at ease when the inevitability of system outages occurs. I’ve used Datadog in the past but my infrastructure grew too fast for their free tier. I also noted pretty intensive CPU server load for their server-side collection agent. Enter Cachet, a free alternative with a good feature set. Most of the big tech companies use Atlassian StatusPage because of its stability and features. It is, however, incredibly expensive at a small and large scale in my opinion.

This tutorial will cover the initial setup of Cachet, which can be technical depending on what stack you decide to use.

In this tutorial, I’ll be using a DigialOcean $5 VPS with a LAMP stack installed. Cachet supports Nginx as well as memcache and Redis caching too. This is going to be the very basic setup type, but I will cover all of the details that most tutorials leave out!

Update: Keep an eye on this tool, it may be available soon and can alleviate some configuration problems!

Let’s Get Started

  1. Prepare your server environment
  2. Redirect your domain
  3. Install Cachet
  4. Secure with LetsEncrypt

Preparing our Server for Cachet

First things first. Spawn a droplet on DigitalOcean or use an existing VPS. I’ll be using Ubuntu 16.04 LTS for this tutorial.

Make sure to spawn with your ssh key

 

Next, login to your server using (in this case) our root user. Authenticate with your private key password.

I recommend following this DigitalOcean tutorial for 16.04 LTS setup. In this case, let’s quickly add our sudo user.

adduser sammy 
usermod -aG sudo sammy

Login as our sudo user.

su - sammy 
mkdir ~/.ssh 
chmod 700 ~/.ssh 
nano ~/.ssh/authorized_keys

Now enter in your public SSH key.

chmod 600 ~/.ssh/authorized_keys

You can now return to root but you will want to be logged in as your sudo user for the remainder of this tutorial.

exit

Redirecting Traffic to our Sub Domain

Next, we will need to redirect all traffic on our sub-domain to your droplet. I use CloudFlare for DNS. All you need to do is make an A record and enter status.example.com as the name and your VPS IP address as the value.

Note: You must turn the cloud to grey so that we can use LetsEncrypt to obtain an SSL certificate. Only after we get the certificate can we use the orange cloud.

 

Installing Cachet

Time to show you what you really came for. I combined a few tutorials I found online into what I think is the best way to install cachet. Note that you can go into much more detail but this should get you up and running quickly. Check out the official documentation if you want to use Docker instead.

Let’s Start

First, let’s update

sudo apt-get update

Now let’s install all the base requirements.

sudo apt-get install git curl apache2 mysql-server php7.0 php7.0-mysql libapache2-mod-php7.0 php7.0-gd php7.0-mcrypt php7.0-cli php7.0-xml php7.0-mbstring

Next, Install Composer, this is a dependency manager for PHP.

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

Now let’s enable Apache2 mod_rewrite, we need this.

sudo a2enmod rewrite

Okay. Now we will install Cachet under our sudo user home directory. Later we will link our public html folder to this directory.

To change to our home directory while logged in as sudo user run

cd ~

Now let’s download Cachet

git clone https://github.com/cachethq/Cachet.git
cd Cachet

Install our PHP Dependencies

composer install --no-dev -o

Make sure to scroll up after running this, any and all errors are reported a ways up your terminal window. If you encounter errors here, you most likely need to reconfigure or install all of the PHP dependencies.

Configuring Cachet

Cachet is controlled by a file called .env  

Let’s create that file while we are still in /home/username/Cachet

nano .env

Put this stuff inside

APP_ENV=production
 APP_DEBUG=false
 APP_URL=http://status.you.com
 APP_KEY=
DB_DRIVER=mysql
DB_HOST=localhost
DB_DATABASE=cachet
DB_USERNAME=cachet
DB_PASSWORD=cachet
DB_PORT=null
CACHE_DRIVER=file SESSION_DRIVER=file QUEUE_DRIVER=sync CACHET_EMOJI=false MAIL_DRIVER=smtp MAIL_HOST=null MAIL_PORT=null MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ADDRESS=null MAIL_NAME=null MAIL_ENCRYPTION=tls REDIS_HOST=null REDIS_DATABASE=null REDIS_PORT=null GITHUB_TOKEN=null

Now we need to create the MySQL database that is listed above. These settings will differ for you.

mysql -u root -p

CREATE DATABASE cachet; 
CREATE USER 'cachet'@'localhost' IDENTIFIED BY 'PASSWORD'; 
GRANT ALL PRIVILEGES ON cachet.* TO 'cachet'@'localhost'; 
FLUSH PRIVILEGES;

Install Cachet

php artisan key:generate 
php artisan config:clear 
chmod -R 777 .env storage database bootstrap/cache

php artisan app:install

Symlinks with Apache2

sudo mv /var/www/html /var/www/html-old
sudo ln -s /home/ubuntu/Cachet/public /var/www/html

Now, .htaccess needs to be allowed to access our apache config. Let’s configure this now.

sudo nano /etc/apache2/sites-available/000-default.conf

My config looks like this

<VirtualHost *:80>
 ServerName status.whitkennedy.com
 ServerAlias status.whitkennedy.com
 DocumentRoot "/var/www/html/"
 <Directory "/var/www/html/"> 
 Options Indexes FollowSymLinks
 AllowOverride All
 Require all granted
 </Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =status.whitkennedy.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>

Note: LetsEncrypt will create a second config for SSL automatically when we run LE. 

Finally, restart Apache

sudo systemctl restart apache2

Securing our Status Page with LE

All we need to do in order to obtain an SSL certificate is run LetsEncrypt.

First, add the repository:

sudo add-apt-repository ppa:certbot/certbot

You’ll need to press ENTER to accept.

sudo apt-get update

And finally, install Certbot from the new repository with apt-get:

sudo apt-get install python-certbot-apache

The certbot Let’s Encrypt client is now ready to use.

Now, Let’sEncrypt!

sudo certbot --apache -d status.example.com

Renewing LE

sudo crontab -e

15 3 * * * /usr/bin/certbot renew --quiet

That’s It!

You now have a neat status page ready for you. You will need to configure the setup page, but it’s pretty simple to setup and get working. You are ready to alert your customers when there are outages!

 

Did I make a mistake? Leave a correction or comment below. Thanks!