PHP and MySQL not communicating

Everything looks OK so I think your installation is not complete. For mysql and php to communicate, you need to install the php5-mysql package :

sudo apt-get install php5-mysql

Install php5-mysql package and use mysqli_connect instead of of mysql_connect


sudo apt-get install php5-mysql

Find Tomcat-version from /etc/init.d/. There should be a file with the name tomcat7, hence 7 is the version

sudo service tomcat7 stop 
sudo service tomcat7 start

Sometimes the machine reboot helps in sorting other issues. After reboot, don't forget to run:

sudo service tomcat7 start