Update: This method no longer works as Ubuntu 12.04 LTS is past end of life. At this point you should be considering upgrading your Ubuntu install rather than upgrading PHP.
Last week I posted a call to action to help sway Ondřej Surý into continuing to support Ubuntu 12.04 LTS with his amazing PPA for the latest and greatest PHP versions. Ondřej was kind enough to take the time to backport the PPA and without ado, here’s how to get PHP 5.6 running on your Ubuntu 12.04 LTS box!
As with any new PPA, you will need
python-software-properties installed so you will have the command to add a PPA. To do so, you can run the following. Note, I snuck in the
update just in case ;)
sudo apt-get update && sudo apt-get install python-software-properties
Once we have that installed, we will need to add the PPA for PHP 5.6:
sudo add-apt-repository ppa:ondrej/php
Great! Now that the PPA is added, you will need to run an
upgrade. Doing so will upgrade your currently installed version of PHP as well as any modules you may have installed.
sudo apt-get update && sudo apt-get dist-upgrade
If you didn’t happen to have PHP installed already, you can install it now:
sudo apt-get install php5.6
Please bear in mind that this will install or upgrade Apache on the system. If you don’t use Apache, you can shut down the service and remove it from the system’s boot sequence. It has never caused any issue with using
nginx for me and I feel it’s a minor inconvenience at best considering you’re getting the latest and greatest version of PHP.
To test the installation, all you need to do is run:
None of this would be possible without Ondřej Surý’s hardwork. I highly recommend showing him some love and donate to the project. He accepts BTC now, too!