It might help to know the specific version of Ubuntu (Long Term Support or other?)
It's not only PHP, but MySQL: requirements on downloads.moodle.org says: PHP 5.4.4,MySQL 5.5.31
And there are extensions to PHP that are also required/highly recommended.
And please provide reference to the FAQ's/docs, etc. you found and used to upgrade PHP. Were they official Ubuntu docs or other blog posting?
Without knowing specifics to operating system version, etc. found this via Google:
http://askubuntu.com/questions/343560/update-server-php-version-to-5-4-10-via-the-command-line
but the above might not apply to your situation and it does contain a twist, but does state:
PHP 5.4.10 is not available in the Ubuntu repositories for 12.04.
Truth in attempting to assist ... don't run Ubuntu but CentOS (unfortunately stuck with 5.10 on some systems). But there is something I've experienced with that OS/setup that might apply to yours (depending) ... conflicts with libraries/extensions when attempting to upgrade what's in place. Have ended up removing PHP and then installing again via yum (package manager) [you probably use apt-get etc. for Ubuntu]. While you are working through this, good idea to shut down apache first because your config.php file would be directly accessible/downloadable (if you've used a login/password that also applies to an ssh login to the system). Broken PHP means .php files are no longer scripts to be run, but ascii pages to server out. While config.php doesn't display anything to a browser, it could be acquired via wget and thus downloader has some info they shouldn't have.
Once you have php upgraded, restart your apache server and check with phpinfo.php file.
If you have tweaked php.ini save a copy out of /etc/ to your home directory for comparing. If you have tweaked mysql (my.cnf) do the same. More than likely you will have to re-tweak. Do NOT copy the old config files to replace the new config files. Matter of fact, it's a good idea to check the config-dist.php file of 2.7 for changes that you can add to your active config.php file.
Am guessing that Ubuntu MySQL similar to CentOS so after upgrading your MySQL don't forget to run mysql_upgrade.
And, in closing, hopefully a true Ubuntu person will respond with their technically correct suggestions/references. ;)
'spirit of sharing', Ken