Running PHP Server Monitor for FREE…..in Azure

By | 31/05/2018

Maybe you have heard of the great monitoring tool, called PHP Server Monitor, it’s a great FREE tool to monitor your services from the outside, requirements are simple:

  • PHP 5.3.7+
  • PHP packages: cURL, MySQL
  • MySQL Database

And it can be downloaded here: https://github.com/phpservermon/phpservermon/releases/latest

Well where does the free Azure part come in?

Azure uses serviceplans, and one of the is free:

App Service Plans | Microsoft Azure

Discover the capabilities and limits available within App Service Plans.

This free plan, can be used with a WebApp, so let get thing done in Azure:

Login to the Azure Portal and choose to create a new WebApp:

 

The App name you chosse, will be the URL for your free website, so choose wisely, it will tell you, if the name you try to pick, is occupied:

 

 

Then click “App service plan/location” and choose “Create New”

 

Fill in the name and click “Pricing Tier”

 

Choose the free plan “F1” and click Apply.

Click “OK”

Click “Create” and wait for Azure to deploy the new site.
(Remember only Windows can run on the free plan, not Linux, but PHP is still supported!)

Check if things are working:

Open browser and ty pe the URL you just made:

Then go and add free SSL to your site with redirect and TLS 1.2:

No need to press save or OK, its done automatically.

Now we need to setup FTP access:

 

Fill in the fields and press save, head to the “overview” pane, left side:

Here you have the infos.

Connect to to the FTP site with your favorite FTP client and upload to the wwwroot (/site/wwwroot) directory, the files you downloaded from PHP Server Monitor (extracted).

Next, as PHP Server Monitor use MySQL, we will enable the In the portal:

Press “ON” and “MySQL general log ON” and SAVE and you have MySQL features 🙂

Now comes the tricky part, Azure do no provide direct access for MySQL, and furthermore, they use a non standard MYSQL port, so we need to fetch theese informations from Azure, this can be done by modifying the config.php of PSM to the following:

The custom MySQL port number, will be delivered in the $servername in the format “hostname:port” so when port changes your system will auto-adapt, therefore is PSM_DB_PORT blank thus needed to be stated for PSM, else it will not work 🙂

Go ahead and test it out, visit:

https://yourname.azurewebsites.net/install.php

You should see this:

Press “Let’s go”

After you have typed the credentials you want to use with PSM, you should see this.

Continue the setup, login to the portal and you get this page:

 

So now PSM is working……..not quite!

We need to setup a cron job! Else nothing will run and check your monitored systems!

There is Azure Webjobs, who actually can do this, you can also set it up, it works, but efter some hours, it’s stopping, claiming that your website have to have “Always-on” enabled for Webjobs to run, hey, let’s go and enable Always-On:

Dammit, that’s not supported in the Free Service Plan, why aren’t whole Azure free 🙂

So what to do now, we need something to visit this URL every 5 minutes:

https://yourname.azurewebsites.net/cron/status.cron.php

I have searched the net, you can run it locally, but when your net goes down, nothin would activate the poller, so i found this one, which is ALSO free 🙂

https://cron-job.org/

Go create an account and set it up:

But as we not want everyone to activate our cron, remember the settings in config.php?

// IP addresses that may run the CRON
$PSM_CRON_ALLOW = array(“xxx.xxx.xxx.xxx”,”yyy.yyy.yyy.yyy”);

Go to https://cron-job.org/en/faq/

Here we find this:

So add this IP to your CRON statement in config.php.

Remember, PSM will throw this error message at you, if the IP received is wrong :

But this is to get rid of bots, “hackers” a.s.o.

Check the logs at cron-job for it:

All is good 🙂

Now go into PSM and setup the servers / services you want to monitor and choose your notification services (email, sms and pushover)

test it out, if it works now, you are all done and have a nice and free monitor solution….running in AZURE 🙂

 

 

Leave a Reply

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