How to install latest PHP 5.4.x on Ubuntu 12.04 LTS (Precise Pangolin)

Disclaimer: Currently 5.5 is the very latest version of PHP, but the common way to install PHP 5.5 has a major disadvantage: It will also install Apache 2.4 or update your Apache 2.2 (standard!) to version 2.4, which will introduce new apache config files, removing current ones (!). No joke. As many apache tutorials teach people to change stuff in /etc/apache2/sites-available/default (which will be removed during Apache 2.4 installation) it might be a bad choice to install PHP 5.5. If you still want to install PHP 5.5, check these articles:
And now, let’s install the latest version of PHP 5.4
There’s an excellent and (usually) hassle-free method to install the latest version of PHP 5.4 with 3 simple bash commands:
1. Add this package-repository to your system. If Ubuntu says that you need to download a key first, then follow the instructions given in the notice.
sudo add-apt-repository ppa:ondrej/php5-oldstable
If you get an error message now, then please do an update first and install the python-software-properties, that need to be necessary to add a package repository:
sudo apt-get update sudo apt-get install python-software-properties
2. Update
sudo apt-get update
Check the available version of PHP (the result is self-explaining, the version on the top is the one that will be installed):
apt-cache policy php5
3. Install PHP 5.4.x
sudo apt-get install php5
Check the installed version of PHP (if this does not show 5.4.x please restart your apache)
php5 -v
Please note: The ondrej/php5-oldstable repository (which is used here) provides the very latest version of the PHP 5.4-branch. Usually a version-update is available a few days after it was been officially released. This is really cool and a big step forward as Ubuntu, Debian, CentOS etc. provide only very old versions by default.
[wp_ad_camp_2]
To UPDATE from PHP 5.3 to 5.4:
It’s also possible to update from any PHP version to 5.4 one with exactly the commands above. But, after doing
sudo apt-get install php5
you’ll have to restart the server with
sudo /etc/init.d/apache2 restart
or
sudo service apache2 restart
Upgraded from PHP 5.3 to 5.4 now every website is BROKEN
php5 -v
PHP Warning: PHP Startup: Unable to load dynamic library ‘/usr/lib/php5/2010052 5+lfs/adodb.so’ – /usr/lib/php5/20100525+lfs/adodb.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP 5.4.45-3+deb.sury.org~precise+1 (cli) (built: Jan 7 2016 15:34:33)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
HELP now what?!?!
FYI- apt-cache policy php5
php5:
Installed: 5.4.45-3+deb.sury.org~precise+1
Candidate: 5.4.45-3+deb.sury.org~precise+1
Version table:
*** 5.4.45-3+deb.sury.org~precise+1 0
500 http://ppa.launchpad.net/ondrej/php5-oldstable/ubuntu/ precise/main i386 Packages
100 /var/lib/dpkg/status
5.3.10-1ubuntu3.21 0
500 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main i386 Packages
500 http://security.ubuntu.com/ubuntu/ precise-security/main i386 Packages
5.3.10-1ubuntu3 0
500 http://us.archive.ubuntu.com/ubuntu/ precise/main i386 Packages
Thanks!!
Thanks for this article. Been searching loads of sites on how to update my PHP to version 5.4. This worked perfect. Keep up the good work!
I make all step and now i have php5.4 in my server but apache cannot load sites, i replace old php.ini with the newer version, i use virtualmind. how to fix? or reverse.
solved most of my problems except it’s missing adodb.so, pam_auth.so and sasl.so.
It works!
Thank you so much!
Great article! thanks
Thanks so much – lifesaver.
Note that this will not upgrade your extensions, so if – as likely – you are using PEAR/PECL extension like APC, uploadprogress, mongo, redis, xhprof … you will need to also :
– update the php5-pear package, which will be broken at this point
– uninstall your PECL extensions and reinstall them : some can be upgraded, but others are at the same version so just doing a “sudo pecl upgrade ” will not work because PECL will not see the PHP version change as an upgrade. Simpler to just uninstall/install again.
Thank you! This solved my problems ;-)