Set up service status page using Cachet

Set up service status page using Cachet
In this article, we will see how to set up service status page using Cachet, an open source alternative to statuspage.io or status.io.
Any tech businesses, startups or companies that provide its services over the internet should always be prepared for inevitable and unexpected incidents that cause downtime or delays. In case of hosting industry, it varies in forms of provider outages, data center blackouts, DDOS attacks, email service delays etc. The best in the industry companies should have a transparent way to convey the service status to their customers in an easy way. There comes the importance of a status page that reflects the operational status of their service. It should show the up time metrics, recent incidents and history etc.
There are many paid options for a status page with above functions. But what if your budget is low? We have an open source status page solution “Cachet” which provides the same beautiful status function at free of cost. Cachet has a beautifully crafted design and has support for more than 10 languages. It also supports updates through JSON API and Two-Factor Authentication. Creation of scheduled maintenance events and metrics from the dashboard makes it acceptable for the status setup of companies.
Let’s see how to install and configure Cachet.
Cachet is recommended to be installed on a small instance separated from other servers or services as the main aim of status page is to convey downtime and delays. Hosting it along with other services may not help the purpose at the time of events.
Cachet is open source and is actively maintained on Github. The prerequisites or requirements to run “Cachet” is as below
Git
Apache2.4+ or Nginx
MySQL Server (SQLite or Postgresql)
CURL
subdomain or even domain like status.domain.com (‘A’ record pointed to the public IP address of the server)
Here, we are using Apache 2.4, PHP 5.6 along with MySQL 5.6 and assumes they are already installed on the server.
Installation
It is recommended to use the latest tagged release for installation. You should use “git checkout” on the latest tag once the git is cloned. v2.3.2 is the latest one at time of this writing.
$ cd /var/www # Or wherever you chose to install web applications to
$ git clone https://github.com/cachethq/Cachet.git
$ cd Cachet
$ git tag -l #list all versions
v0.1.0-alpha
v1.0.0
v1.1.0
v2.0.0
v2.1.0
v2.3.2
$ git checkout v2.3.2
Configuration
By default, Cachet comes with a sample configuration file “.env.example”. We will need to rename the file to .env or make a copy as .env. Once renamed, we can edit the file and add the MySQL & Cache details. A sample file is as below.
APP_ENV=production
APP_DEBUG=false
APP_URL=http://localhost
APP_KEY=SomeRandomString
DB_DRIVER=mysql
DB_HOST=localhost
DB_DATABASE=cachet
DB_USERNAME=homestead
DB_PASSWORD=secret
DB_PORT=null
CACHE_DRIVER=apc
SESSION_DRIVER=apc
QUEUE_DRIVER=database
CACHET_EMOJI=false
MAIL_DRIVER=smtp
MAIL_HOST=xyz.com
MAIL_PORT=25
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ADDRESS=null
MAIL_NAME=”Demo Status Page”
MAIL_ENCRYPTION=tls
REDIS_HOST=null
REDIS_DATABASE=null
REDIS_PORT=null
GITHUB_TOKEN=null
Change the APP_URL to the URL where you are hosting the Cachet. The DB_DRIVER variable holds what database you are using. If you have installed APC cache with PHP, you can use APC in CACHE_DRIVER and SESSION_DRIVER. Otherwise, simply use CACHE_DRIVER=file and SESSION_DRIVER=file. Using incorrect cache values will lead to errors at the time of setup. Further, you can setup email ID from which Cachet can send status notifications to the subscribers. It is recommended to use SMTP authentication here. Advanced options include usage of REDIS which is optional.
Setting up Database
Cachet uses a database to store the data. It can be MySQL, SQLite or Postgresql. Create a new database in MySQL using below commands.
$mysql -u root -p
mysql>CREATE DATABASE cachet;
mysql>CREATE USER ‘cachet’@’localhost’ IDENTIFIED BY ‘RANDOM_PASSWORD’;
mysql>GRANT ALL PRIVILEGES ON cachet.* TO ‘cachet’@’localhost’;
mysql>FLUSH PRIVILEGES;
Installing Composer
Cachet uses a PHP dependency manager “Composer” to install the app. Use the below commands to install Composer.
$curl -sS https://getcomposer.org/installer | php –install-dir=/usr/local/bin –filename=composer
$composer install –no-dev -o
You can also try “composer install –no-dev -o –no-scripts” if you get stuck at the composer stage.
Setting the application key
We need to set APP_KEY before we go ahead. To generate, run
$ php artisan key:generate
The APP_KEY will be added automatically to the .env file. Never change the APP_KEY once you started using Cachet for production. All the data stored is encrypted with this key and changes will result in loss all encrypted data.
Using the install command
To complete installation of Cachet, run the following command.
$ php artisan app:install
If all goes well, you will get the message that the installation is successful. If you find any errors, you can try the following,
php artisan config:clear
rm -rf bootstrap/cache/*
chmod -R 777 .env storage database bootstrap/cache
Also, check the logs located at Cachet/storage/logs/laravel-YYYY-MM-DD.log
Running Cachet on Apache
The step remaining is to configure Cachet to run on Apache. Make sure that Apache has the rewrite module enabled. Add a virtual host entry in httpd.conf similar to the one below.
<VirtualHost *:80>
ServerName status.domain.com
# Or whatever you want to use
ServerAlias status.domain.com
# Make this the same as ServerName
DocumentRoot “/var/www/Cachet/public”
<Directory “/var/www/Cachet/public”>
Require all granted
# Used by Apache 2.4
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Restart Apache service. Make sure that the domain or the sub domain is pointed to the server IP. Once restarted, browse the domain given in the APP_URL in the browser. You will see setup page of Cachet as in the images below.
Once setup is completed, you will be redirected to a login page and the dashboard thereafter.
Tips for control panel installed servers
Git and Composer might be installed already on the servers. You can skip the steps for them. While creating subdomains or domains where you wish to add Cachet, make sure that Apache Document root is pointed to <sub domain directory>/Cachet/public directory as the contents of the Cachet website part is in that directory. It is not recommended to edit the httpd configuration files manually if you use a control panel. Also, make sure that permissions are 755 for the folders as some control panels don’t allow the usage of 777.
Conclusion
Cachet is a beautiful and open source alternative to many of status page paid services. It is supported on Linux/ Unix and even in Windows servers. Cachet with its support of APIs allows automated metric and status collection. All you have to do is a PHP hacky thing to create the code or plugins for it. Hope you will try it.