apt-get update updates only the package lists. To actually upgrade the packages you have to run:
sudo apt-get upgrade
or
sudo apt-get dist-upgrade
More info here.
If you ran the above commands but the packages still were not upgraded, probably you didn't add Ondřej Surý's PHP PPA to your system.
Run the following to add the PPA:
For PHP 5.5, PHP 5.6 and PHP 7.0:
sudo apt-add-repository ppa:ondrej/phpFor PHP 5.4 (Deprecated, upgrade at least to PHP 5.5):
sudo apt-add-repository ppa:ondrej/php5-oldstableFor PHP 5.5 (Deprecated, use
ppa:ondrej/php):sudo apt-add-repository ppa:ondrej/php5For PHP 5.6 (Deprecated, use
ppa:ondrej/php):sudo apt-add-repository ppa:ondrej/php5-5.6
Then update the package lists and perform the upgrade:
sudo apt-get update
For PHP 5.5:
sudo apt-get install php5.5
For PHP 5.6:
sudo apt-get install php5.6
For PHP 7:
sudo apt-get install php7.0
Release upgrade
If you want to install the latest PHP (for example PHP7) but you want to stick to the release's packages intead of hacking the sources around; and you want to do a full-release upgrade (for example you are in Ubuntu 14.04 -which does not have php7- and you want to go to Ubuntu 16.04 -which does- then you can do:
do-release-upgrade
Now you should have the latest PHP version.
Answer from Eric Carvalho on askubuntu.comapt-get update updates only the package lists. To actually upgrade the packages you have to run:
sudo apt-get upgrade
or
sudo apt-get dist-upgrade
More info here.
If you ran the above commands but the packages still were not upgraded, probably you didn't add Ondřej Surý's PHP PPA to your system.
Run the following to add the PPA:
For PHP 5.5, PHP 5.6 and PHP 7.0:
sudo apt-add-repository ppa:ondrej/phpFor PHP 5.4 (Deprecated, upgrade at least to PHP 5.5):
sudo apt-add-repository ppa:ondrej/php5-oldstableFor PHP 5.5 (Deprecated, use
ppa:ondrej/php):sudo apt-add-repository ppa:ondrej/php5For PHP 5.6 (Deprecated, use
ppa:ondrej/php):sudo apt-add-repository ppa:ondrej/php5-5.6
Then update the package lists and perform the upgrade:
sudo apt-get update
For PHP 5.5:
sudo apt-get install php5.5
For PHP 5.6:
sudo apt-get install php5.6
For PHP 7:
sudo apt-get install php7.0
Release upgrade
If you want to install the latest PHP (for example PHP7) but you want to stick to the release's packages intead of hacking the sources around; and you want to do a full-release upgrade (for example you are in Ubuntu 14.04 -which does not have php7- and you want to go to Ubuntu 16.04 -which does- then you can do:
do-release-upgrade
Now you should have the latest PHP version.
For newest updating process use the following command
sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
Then run the following command in terminal
sudo apt-get update
This is worked well when installing php 5.5,5.6 and 7.0
If there some errors this command will resolve the errors
sudo dpkg --configure -a
Update 2020-10-14: For versions upto 7.*
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
Then
sudo apt install php7.2
Here also you can use this for php 7.0,7.1,7.3 to 7.4
After updating process you can use below command to install extensions
sudo apt update
sudo apt install php-xml
or you can use like below
sudo apt install php7.2 php-xml
Update 2021-01-31: For versions upto 8.*
sudo apt-add-repository ppa:ondrej/php
sudo apt update
Then
sudo apt install -y php8.0 php8.0-cli php8.0-common
Videos
You can uninstall composer, and while re-installing it will ask you to point at your PHP directory which is going to be C:\wamp64\bin\php (usually) at that point you can choose which PHP version you would want to use. good luck.

This means you have yet another installation of PHP in your system. Check your Programs in Control Panel and remove such installation.
However, you can modify your PATH environment variable as well. Procedure
Just remove the path that points to any PHP installation directory.
Else, otherwise, if you are unsure about changing the PATH variable (which can lead to serious problems if not set well), you can just delete the directory that the PATH variable points to.... (I mean the PHP directory)
The totally better solution is to add the path of your PHP7 bin directory at the beginning of the PATH variable. You should also make available composer in this PHP7 bin directory.
Such as, replace the C:\php in your path with C:\wamp\bin\php7 or whatever the location of the PHP7 path is..
In command prompt type below
set PATH=%PATH%;C:\path\to\php
Where C:\path\to\php is the folder where your php.exe file is located. After this run
C:\>php -v
than you will see something like
PHP 7.3.6 (cli) (built: May 29 2019 12:11:00)
UPDATE:
If you find that when you restart your computer, this solution will not work anymore:
Set the Path like as following:
Step 1 - Click on the
Windowsicon

Step 2 - Click on the
Settingsicon

Step 3 - Click on
System

Step 4 - Click on
About

Step 5 - Click on
System info

Step 6 - Click on
Advanced system settings

Step 7 - Click on
Environment variables...

Step 8 - Select
Pathrow and then clickEdit

Step 9 - Click
Newand then clickBrowse, then in the next panel which will open you need to select the folder you want in thePath. For the initial premise of this guide i will add the folderC:\Users\NewFolderInPathNote: Replace your PHP installed path(e.g:
C:\Program Files\php) with the above path .

Step 10 - Click
OKand click everyOKbutton you will encounter to close every previous windows.

You just need to find out where is your PHP folder.
- If you are using XAMPP or WAMP then you will see a php folder.
- You just need to go into the php folder using your cmd using command
cd \xampp\php (FOR XAMPP)
cd \wamp\php (FOR WAMP)
- And then just type in this command
php -v
- Then you will see something like
PHP 5.6.11 (cli) (built: Jul 9 2015 20:55:40) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies