#!/bin/bash
#
#  Test LAMP by checking Apache, MySQL, and PHP
#  Requires: apache2, php5-mysql, libapache2-mod-php5, mysql-server
#

# Check Apache is running; requires network connection so verify that
check=`ping -c 2 www.ubuntu.com |grep "2 received"`
if [ -n "$check" ]; then
  run1=`w3m http://127.0.0.1/ | grep "404"`
  if [ -n "$run1" ]; then
    echo "FAIL: apache is not running."
    exit 1
  fi
fi

# Check if MySQL server is running
run2=`netstat -tap | grep mysql`
if [ -z "$run2" ]; then
  echo "FAIL: mysql is not running."
  exit 1
fi

# Check PHP
run3=`php -r 'phpinfo();' | grep 'PHP License'`
if [ -z "$run3" ]; then
  echo "FAIL: php is not running."
  exit 1
fi

exit 0
