How to install Cachet status page system on Ubuntu Server 18.04

Keep clients and users apprised of server downtime with the Cachet status page system.

Image: Jack Wallen

One of the things the Linux server doesn't have is an elegant way to communicate to users downtime and outages. This can be crucial information to users of your services so that they know when to prepare for servers being down for maintenance (or other reasons).

Fortunately, there is an outstanding tool you can install on your Linux servers that can easily inform those users of pending downtime. That tool is Cachet. Cachet can be installed on almost every Linux distribution, but I will walk you through the process of installing this tool on the Ubuntu Server 18.0 platform.

SEE: Disaster recovery and business continuity plan (Tech Pro Research)

What you need

The only things you need to get Cachet up and running are:

  • Running instance of Ubuntu Server 18.04.
  • User account with sudo privileges.

Although I will demonstrate the installation without using SSL, you can optionally configure Cachet to work with your installed certificates.

Installing dependencies

The first thing we must do is install the necessary dependencies. Log into your Ubuntu Server and issue the following command to take care of these first dependencies:

sudo apt install curl wget vim git unzip socat bash-completion -y

Next, PHP must be installed. To take care of this, issue the following command:

sudo apt install php7.2 php7.2-cli php7.2-fpm php7.2-common php7.2-xml php7.2-gd php7.2-zip php7.2-mbstring php7.2-mysql php7.2-pgsql php7.2-sqlite3 php7.2-opcache php-apcu -y

Install the database

We'll use MySQL as our database, which can be installed with the command:

sudo apt-get install mysql-server -y

When the installation completes, secure the database server with the command:

sudo mysql_secure_installation

Answer no for the VALIDATE PASSWORD plugin and then create a secure password for the MySQL administrator. Answer yes (with a Y) for the remaining questions.

Next, we must create the database. Log into the MySQL prompt with the command:

sudo mysql -u root -p

Create the database, the database user, and give the user the necessary permissions with the following commands:

CREATE DATABASE cachetdb;
GRANT ALL ON cachetdb.* TO 'cachet' IDENTIFIED BY 'PASSWORD';
FLUSH PRIVILEGES;
exit

Where PASSWORD is a strong, unique password.

Install and configure NGINX

Now we need a web server. If your server already includes either Apache or NGINX, you can skip the installation section. To install NGINX, issue the command:

sudo apt-get install nginx -y

Configure NGINX with the command:

sudo nano /etc/nginx/sites-available/cachet.conf

Paste the following into this new file:

server {

  listen 80;
  listen [::]:80;
  listen 443 ssl;
  listen [::]:443 ssl;

  server_name SERVERNAME;

  root /var/www/cachet/public;

  index index.php;

  location / {
    try_files $uri /index.php$is_args$args;
  }

  location ~ \.php$ {
    include fastcgi_params;
    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_index index.php;
    fastcgi_keep_conn on;
  }

}

Where SERVERNAME is either the name or IP Address of your server. Save and close that file.

If you need to include SSL, you need to add the following lines in the cachet.conf file (below the index line):

ssl_certificate /path/to/certificates/CERTNAME.cer;
ssl_certificate_key /path/to/certificates/DOMAIN.key;
ssl_certificate /path/to/certificates/CERTNAME.cer;
ssl_certificate_key /path/to/certificates/DOMAIN.com.key;

Where /path/to/certificates is the full path to your SSL certificates, CERTNAME is the name of your .cer files, and DOMAIN is the domain used for your certificates.

Activate the new configuration with the command:

sudo ln -s /etc/nginx/sites-available/cachet.conf /etc/nginx/sites-enabled/

Reload NGINX with the command:

sudo systemctl reload nginx

Install composer

Now we need to install Composer. This is done with the following five commands:

  • php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
  • php -r "if (hash_file('sha384', 'composer-setup.php') === '48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
  • php composer-setup.php
  • php -r "unlink('composer-setup.php');"
  • sudo mv composer.phar /usr/local/bin/composer

Install Cachet

We finally can install Cachet. First, create a new directory with the command:

sudo mkdir -p /var/www/cachet

Change into that new directory with the command cd /var/www/cachet and download the Cachet source code with the command:

git clone -b 2.4 --single-branch https://github.com/cachethq/Cachet.git .

Copy the configuration file with the command:

cp .env.example .env

Open the file for editing with the command nano .env. In this file, you'll want to change the following:

DB_DRIVER=mysql
DB_HOST=localhost
DB_UNIX_SOCKET=null
DB_DATABASE=cachetdb
DB_USERNAME=cachet
DB_PASSWORD=PASSWORD
DB_PORT=3306
DB_PREFIX=

Where PASSWORD is the password you created for the cachet user. If you want to optionally make use of the email system, you'll also need to edit the following section (to reflect your SMTP server settings):

MAIL_DRIVER=log
MAIL_HOST=null
MAIL_PORT=null
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ADDRESS=null
MAIL_NAME=null
MAIL_ENCRYPTION=tls

Note: Email settings can also be set during the final set-up phase. Save and close that file.

Install the Cachet dependencies with the following command:

composer install --no-dev -o

Set up the application and install Cachet with the following commands:

php artisan key:generate
php artisan cachet:install

After running the second command above, you'll be prompted to answer two questions. Make sure to answer No to both of these (otherwise the set up will fail). When the installation completes, change the ownership of the cachet directory with the command:

sudo chown -R www-data:www-data /var/www/cachet

Complete the set up

You can now point your browser to http://SERVER_ADDRESS/setup (where SERVER_ADDRESS is either the domain or IP of the server). You will be greeted with the set up completion wizard (Figure A).

Figure A

Figure A: Completing the Cachet setup with a web-based GUI.

Select Database as the option for the three drivers, and fill out your mail options. Click Next and continue configuring Cachet (such as site name, admin account, etc.). When you finish the set up you'll be prompted to log in with the administrator account and then find yourself on the Cachet dashboard (Figure B).

Figure B

Figure B: The Cachet Dashboard.

Congratulations, you're ready to start using the Cachet status page system. Using the system is fairly straightforward. Spend a bit of time poking around the dashboard, and you'll figure it out fairly quickly.

Also see

By Jack Wallen

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.