Upgrading to PHP 5.4 on Ubuntu 12.04 LTS

File this under “mostly for my own benefit”, since I often forget how I accomplished something when I need to go back and do it again.

As of March 15, 2013, PHP 5.3.x will only receive “critical fixes” and people are encouraged to upgrade to 5.4 or 5.5. And sometime in 2014, 5.3.x will not longer be supported at all. All of the Linux servers I’m working on now are running Ubuntu 12.04 LTS, which currently provides PHP 5.3.10, so I decided to look into what it takes to update to 5.4.x on these boxes.

It’s simple…

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php5-oldstable
sudo apt-get update
sudo apt-get install php5
sudo service apache2 restart
#(if it doesn't do it automatically)

“sudo add-apt-repository ppa:ondrej/php5-oldstable” adds a 3rd party repository for php 5.4.x. Removing “-oldstable” will get you 5.5.x instead.