This guide will not cover Ubuntu 12.04 at this time as the PPA from ondrej appears to upgrade Apache 2.2 to 2.4, and I have not been able to install this cleanly. If PHP 5.5 or 5.6 is needed, I am going to have to suggest migrating to Ubuntu 14.04 for the time being.
The version of PHP that ships with Ubuntu 14.04 is PHP 5.5, which is starting to get a bit outdated. Oftentimes, people will want to use a newer version of PHP, such as PHP 5.6 or PHP 7.0. This is easy enough to do, however you should always test this out on a dev server before applying to production just in case you run into problems.
On Ubuntu, it looks like the preferred method is to use the PPA from ondrej. So to get started, first update your existing repos, then add the new PPA:
# Update PHP 5.5 on Ubuntu 14.04 to PHP 5.6 [[email protected] ~]# apt-get -y update [[email protected] ~]# apt-get install software-properties-common [[email protected] ~]# add-apt-repository ppa:ondrej/php [[email protected] ~]# apt-get -y update [[email protected] ~]# apt-get -y install php5.6 php5.6-cli php5.6-mysql php5.6-mcrypt php5.6-mbstring php5.6-curl php5.6-gd php5.6-intl php5.6-xsl php5.6-zip [[email protected] ~]# a2dismod php5 [[email protected] ~]# a2enmod php5.6 [[email protected] ~]# service apache2 reload # Update PHP 5.5 on Ubuntu 14.04 to PHP 7.0 [[email protected] ~]# apt-get -y update [[email protected] ~]# apt-get install software-properties-common [[email protected] ~]# add-apt-repository ppa:ondrej/php [[email protected] ~]# apt-get -y update [[email protected] ~]# apt-get -y install php7.0 php7.0-cli php7.0-mysql php7.0-mcrypt php7.0-mbstring php7.0-curl php7.0-gd php7.0-intl php7.0-xsl php7.0-zip [[email protected] ~]# a2dismod php5 [[email protected] ~]# a2enmod php7.0 [[email protected] ~]# service apache2 restart
Perhaps you find that your application doesn’t work with PHP 5.6 or PHP 7.0, so you want to roll back to stock PHP 5.5 instead:
# Downgrade PHP 5.6 on Ubuntu 14.04 to PHP 5.5 [[email protected] ~]# apt-get install ppa-purge [[email protected] ~]# add-apt-repository -r ppa:ondrej/php [[email protected] ~]# ppa-purge ppa:ondrej/php [[email protected] ~]# apt-get remove php5.6-common php5.6-cli [[email protected] ~]# apt-get autoremove [[email protected] ~]# apt-get install php5 php5-cli php5-common [[email protected] ~]# a2enmod php5 [[email protected] ~]# service apache2 restart # Downgrade PHP 7.0 on Ubuntu 14.04 to PHP 5.5 [[email protected] ~]# apt-get install ppa-purge [[email protected] ~]# add-apt-repository -r ppa:ondrej/php [[email protected] ~]# ppa-purge ppa:ondrej/php [[email protected] ~]# apt-get remove php7.0-common php7.0-cli [[email protected] ~]# apt-get autoremove [[email protected] ~]# apt-get install php5 php5-cli php5-common [[email protected] ~]# a2enmod php5 [[email protected] ~]# service apache2 restart