Monitor file changes in your Website

This script can be used to notify you when a file changed in your website. This is useful when you want to know when a file changed or your site is hacked and you to monitor your site for file changes so you know when hacker upload or modify a file.

First you need to add your web site to GIT.

This can be with

cd /var/www/html
git init
git add .
git commit -a -m "inital commit"

Replace /var/www/html with actual DocumentRoot for your web site.

Every time you modify or add a file, you need to commit it to git you will get alerted. You can commit a new file to git with command

git add FILE_NAME
git commit -a

Create a file

mkdir /usr/serverok/
vi /usr/serverok/check-files.php

Add following content


In the script, replace /var/www/html with actual document root of your web site. Change email and site name with your email and domain name.

Set following cronjob.

0 * * * * /usr/bin/php /usr/serverok/check-files.php

Cronjob will run every 1 hour and email you if any file change is detected. You can modify cronjob if you want to monitor more frequently, every 1 hour will be fine for most uses.

If you have a folder or file that you need to ignore, you can create a file with name ".gitignore" and add path to file/folder in it, git will ignore files/folders listed in it.

Comments

Leave a Reply

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