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