PHP Server Monitor – Windows Setup Guide

Want to use PHP Server Monitor to track the uptime status of your devices? Not ready to build a CentOS or Ubuntu Server instance, but would rather have a Windows-install?

There are three primary methods to configuring an AMP stack.

  1. LAMP (Linux, Apache, MySQL, PHP)
  2. WAMP (Windows Desktop or Server, Apache, MySQL, PHP)
  3. IIS/PHP (Windows Server with Internet Information Services Role, MySQL, PHP)

This will be focusing on the Windows Desktop option. It’s lower performance than Linux or IIS, but it sure is easier for beginners, and easier to move between hosts.

Win10 + XAMPP

This tool has been around for many, many years. The code base made be old, but it’s free, still updated, and very reliable.

Appropriate for a small one-off server.

In my case, I’m using a Win10 Enterprise VM and loading on XMAPP.

 

https://www.apachefriends.org/index.html

Go snag XAMPP (32 Bit only for Windows). There is also a portable version if you don’t want a permanent install (e.g. run off a thumb-drive).

Run the installer, it is recommended to not install to Program Files directories due to weird permissions with UAC. Recommend installing to root, e.g. C:\XAMPP.

You only need Apache, MySQL, and PHP.

Start it, let it open up the XAMPP control panel.

 

Download PHPServerMonitor

Go to C:\xampp\htdocs, copy the contents to C:\xampp\htdocs.old, create the directory if it does not exist.

Go snag a download of PHP Server Monitor — https://github.com/phpservermon/phpservermon

Click download to ZIP in the upper right.

Unzip the ZIP contents into your operating PHP directory, by default: C:\xampp\htdocs

Download Composer

Composer is a dependency packager — it downloads and auto-installs the pieces that PHP Server Monitor depends on.

https://getcomposer.org/download/

The installer will add the composer.exe file into your Windows environment path, allowing you to run it from command line in any directory. The installer should also auto-detect your xampp install, and the operating directory of C:\xamp\htdocs.

When the command “composer install” is run, it will look for a .JSON file inside the directory it is being run. This contains the instructions of what composer needs to do.

 

Start > cmd.exe > Right-Click > Run as Administrator
cd C:\xampp\htdocs
composer install

Give it a few minutes, and it should auto-download all of the dependencies.

Start the Server Up, Build the Database

  1. Browse to C:\xampp\htdocs\
    1. Find config.php.sample, Copy/Paste it in the same directory, and rename to config.php
  2. Open XAMPP Control panel, if they are running, stop Apache and MySQL. Then start them both up, MySQL first.
  3. Browse to: http://localhost
    1. It should redirect you to http://localhost/install.php
    2. Hopefully, you see some pre-requisite success messages.
  4. If so, open XAMPP, click “Shell”
mysql -u root -p
[Password is blank, just hit enter]

create database phpsrvmon;
#Change your user and password in quotes
create user phpsrvmon_user@localhost identified by "user_password";
#Make this match the user above
grant all privileges on phpsrvmon.* to phpsrvmon_user@localhost;
flush privileges;
quit

Configure the Database

Open XMAPP, ensure both stop/start Apache and MySQL.

Browse to: http://localhost, you should be redirected back to: http://localhost/install.php

  • Application Base URL: http://something.yourdomain.com
  • Database Host: localhost
  • Database Port 3306 (You can confirm within XAMPP.
  • Database Name: phpsrvmon
  • Database User: phpsrvmon_user (or whatever you entered)
  • Database Password: user_password (you picked something different right?)
  • Table Prefix: psm_

Save Configuration

You may get an error, “Unable to save your configuration”. It should cough out the code you can copy/paste into a config.php file.

If so, open your config.php file, and overwrite the code with what it provided. If you don’t have it, it looks like this:

<?php
define('PSM_DB_HOST', 'localhost');
define('PSM_DB_PORT', '3306');
define('PSM_DB_NAME', 'phpsrvmon');
define('PSM_DB_USER', 'phpsrvmon_user');
define('PSM_DB_PASS', 'your password');
define('PSM_DB_PREFIX', 'psm_');
define('PSM_DB_BASEURL', 'http://something.yourdomain.com');

Save the file config.php, go back to XAMPP, and stop/start Apache to load in the new settings.

Create your Web-Account

Go back to http://localhost

You should get the message, “Sweet, your database connection is up and running!”

Now create a username, password, and email — this is for actually using the website, nothing to do with the database infrastructure.

Create a Monitor

Login to your site, it will redirect to your web-URL by the way, so ensure it can be resolved by your DNS server. If you’re desperate, you can always edit the Windows HOSTS file.

Open the “Servers” tab.

Add New (+) > Add a DNS address or IP, select a ping, or a matching service/port. It is important to set a threshold, I typically use a Warning Threshold of 2, meaning after 1 query it is a warning (amber), after 2 it is an alert (red). I use a timeout of 10 seconds usually, just in-case latency is high. Check off the users you want to be able to view the monitor.

Configure the Scheduler/CRON

We have our monitors, but we need a way to run the port/ping query, this is not run automatically. On Linux, it is run via CRON. On Windows, it is run via the Task Scheduler.

  • Start > Run > taskschd.msc > OK
    • Task Scheduler Library > Right-Click > Create Basic Task
      • Name: “PHP Server Monitor Query”
      • Run: One Time
      • Action: Start a Program: C:\xampp\php\php.exe
      • Add Arguments:C:\xampp\htdocs\cron\status.cron.php –timeout=1
        • The timeout number is the timer of cron in minutes, default is 10 minutes.
  • Next > Open Properties Box
    • Check: Run whether user is logged on or not.
  • Trigger Tab > Select > Edit
    • One Time, Advanced Settings > Repeat Task Every: 5 minutes, then change 5 to 1, for a duration of: Indefinitely
      • Note — If you have a large number of monitors (e.g. 100+) increase the timer appropriately. A general guideline is 20 seconds for each 100 monitors.
      • Ensure your Repeat Task Every number matches your timeout value in the Arguments.
    • Stop task if it runs longer than: 30 minutes, adjust to 3 minutes.
  • Conditions Tab > Uncheck power settings that relate to AC and battery power.
  • Settings Tab
    • Check: Allow task to be run on demand
    • Stop the task if it runs longer than: 1 hour
    • Check: If the running task does not end when requested, force it to stop.
    • If the task is already running, then the following rule applies: Stop the existing instance.
  • OK > Enter your password to run the task as an adminstrator when logged off.

Final Settings / Little Details

Autostart

While in XAMPP, configure the services to autostart on boot. Click: Config > Check: Apache, MySQL

Fixing Queries (Important!)

By default, you  will only get a single query every 10 minutes, as the stock XAMPP php.ini file causes the cron script to get stuck in running mode until it times out after 10 minutes.

Open Notepad, and open: C:\xampp\php\php.ini

Ctrl+F to search, search for: extension=sockets

There will be a comment in front of it ” ; “, remove the semicolon to make the code active, save php.ini. Go back to XAMPP, and stop/start Apache.

 

Now get those monitors added, and keep and eye on all your important gear. Good luck!

Leave a Reply

Your email address will not be published. Required fields are marked *