Now that php5 no longer has support in 2017, a lot of webmasters are trying to upgrade their php to php7.
Here’s how to upgrade your php5 to php7.
First install python-software-properties and then add ppa:ondrej/php-7.0 to your apt repo.
sudo apt-get install python-software-properties sudo add-apt-repository ppa:ondrej/php-7.0
if this command gives you this error.
Cannot add PPA: 'ppa:~ondrej/ubuntu/php-7.0'. The user named '~ondrej' has no PPA named 'ubuntu/php-7.0'
Then it must be because ppa:~ondrej/ubuntu/php-7.0 is deprecated. So we must try another solution. But if it goes through, then proceed and install php7 using this command.
sudo apt-get update && sudo apt-get install php7.0
Now, If you have encounter an error, try this command instead.
sudo add-apt-repository ppa:ondrej/php sudo apt-get update sudo apt-get install php7.0
If you get an error like cannot locate package php7.0, then it’s because php7.0 is not included on the repo ppa:ondrej/php. So we have to try another solution. This time we will use dotdeb repo.
First you have to determine if your ubuntu distribution is base on Jessie or Wheezy.
Then add the following to your /etc/apt/source.list
For jessie distribution:
deb http://packages.dotdeb.org jessie all deb-src http://packages.dotdeb.org jessie all
or for wheezy distribution
deb http://packages.dotdeb.org wheezy all deb-src http://packages.dotdeb.org wheezy all
after that, we need to fetch the GnuPG key.
cd /tmp wget https://www.dotdeb.org/dotdeb.gpg sudo apt-key add dotdeb.gpg
If everything goes well, you should be able to install php7 by this command:
sudo apt-get update && sudo apt-get install php7.0