I suggest trying to google-ing your question. You are not the first to ask how to upgrade a technology.
The first result for me after googling "how to update php on linux" is good stack exchange thread: http://askubuntu.com/questions/565784/how-do-i-upgrade-php-version-to-the-latest-stable-released-version
This link may not be for you, and if it is not, I suggest trying other links until you get it to work.
A general practice is to stick to official packages when upgrading theses types of technologies. Sometimes they are not available for your environment, sometimes they are. If they are not its generally because you are running "out of date" software, for example, google chrome only goes up to version 38 on Ubuntu 12. I had to upgrade to 14.04 to get chrome version support again.