Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Deploying PhpServerMon With Docker

PHP Server Monitor is a free and open source tool that one can use as an alternative to Uptime Robot. It's not very sexy, but it should get the job done, and puts you more in control.

  • It has the ability to alert you if your site goes down, and even if your SSL certificate is about to expire.
  • It can alert you via various methods, including email, SMS, Telegram, and others.

Prerequsites

You need a VPS/server with Docker and Docker-Compose installed.

Steps

Create a docker-compose.yml file:

editor docker-compose.yml

... with the following contents:

version: '3.8'

services:

  phpservermonitor:
    image: phpservermonitor/phpservermon:latest
    container_name: phpservermonitor
    restart: always
    environment:
      - TIME_ZONE=${TIME_ZONE}
      - PSM_REFRESH_RATE_SECONDS=15
      - PSM_AUTO_CONFIGURE=true
      - MYSQL_HOST=db
      - MYSQL_USER=phpservermonitor
      - MYSQL_PASSWORD=${DB_PASSWORD}
      - MYSQL_DATABASE=phpservermonitor
      - MYSQL_DATABASE_PREFIX=psm_
    ports:
      - 80:80
    #volumes:
    # - /sessions
    depends_on:
     - db

  db:
    image: mariadb
    container_name: db
    restart: always
    environment:
      - MYSQL_RANDOM_ROOT_PASSWORD=1
      - MYSQL_USER=phpservermonitor
      - MYSQL_PASSWORD=${DB_PASSWORD}
      - MYSQL_DATABASE=phpservermonitor
    volumes:
      - mysql-data:/var/lib/mysql/phpservermonitor

volumes:
  mysql-data:
    driver: local

Now we need to create the environment file with the settings to use:

editor .env

Fill it with the following content, changing the settings as appropriate:

# Set the timezone. List them by running the following command in BASH shell
# timedatectl list-timezones
TIME_ZONE="Europe/London"

# Set a password for the database.
# You should use a strong random string
# Never change this once you have deployed
DB_PASSWORD="setYourPasswordHere"

Deploy

Now you can deploy by simply running:

docker-compose up

This should automatically pull the Docker images it needs the first time you run it.

Updating

If you wish to update at a later point, then you should only need to run the following:

docker-compose pull
docker-compose up

Calling docker-compose up whilst containers are already running will replace them if there are new images [1].

Getting Started

Now that we have deployed, navigate to your server's IP or FQDN and you will see the following. Click Lets go.


Fill in the form and click Install to create the administrators account.


You will see a screen telling you that it installed successfully. Click Go to your monitor.


Log in with the username and password you just created.


When you log in, you will see this screen with the default monitors:


If you press this button you get a nicer view in my opinion.

Add Server

To add a server, click the hamburger menu and click Servers.


Then press the button to Add new and just fill in the forms. It's all really straightforward.

References

Last updated: 26th September 2021
First published: 26th September 2021

This blog is created by Stuart Page

I'm a freelance web developer and technology consultant based in Surrey, UK, with over 10 years experience in web development, DevOps, Linux Administration, and IT solutions.

Need support with your infrastructure or web services?

Get in touch