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/php
    
  • For PHP 5.4 (Deprecated, upgrade at least to PHP 5.5):

    sudo apt-add-repository ppa:ondrej/php5-oldstable
    
  • For PHP 5.5 (Deprecated, use ppa:ondrej/php):

    sudo apt-add-repository ppa:ondrej/php5
    
  • For 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.com
Top answer
1 of 5
108

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/php
    
  • For PHP 5.4 (Deprecated, upgrade at least to PHP 5.5):

    sudo apt-add-repository ppa:ondrej/php5-oldstable
    
  • For PHP 5.5 (Deprecated, use ppa:ondrej/php):

    sudo apt-add-repository ppa:ondrej/php5
    
  • For 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.

2 of 5
13

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
🌐
sebhastian
sebhastian.com › how-to-update-php
How to update PHP version | sebhastian
July 25, 2022 - To install PPA easily, you need ... the PPA sudo add-apt-repository ppa:ondrej/php # 👇 refresh the package manager sudo apt-get update # 👇 install latest PHP version sudo apt -y install php8.1...
Discussions

how can i update php cli version from command prompt on Windows? - Stack Overflow
i am using windows os, want to update php version to PHP 7.2.5 or grater currently using PHP 7.2.3 More on stackoverflow.com
🌐 stackoverflow.com
powershell - How to update specific PHP version on Windows? - Stack Overflow
Is there a way to update PHP via Terminal (Windows PowerShell) or Git Bash? Currently, I am on PHP 7.2, but I wanted to update it to 8.2. More on stackoverflow.com
🌐 stackoverflow.com
Find PHP version on windows command line - Stack Overflow
DB(mariadb/mysql)version type ... mariaDb version ... It is most likely that php is not in your specified path. Try to issue the php command with the full path, for example: ... Please note, that this is just an example, your php installation might be in a different directory. ... For Beginners to anything php, it is usually stored in the C:/ path folder of your PC (My Computer). ==On Windows== 1.Click Start Menu button 2.Type cmd and press ... More on stackoverflow.com
🌐 stackoverflow.com
How to Uninstall PHP in Windows 10
Just to let you know: you can download and install mysql as well. More on reddit.com
🌐 r/PHPhelp
6
3
December 8, 2017
🌐
HelpSpot
support.helpspot.com › index.php
3.1. Upgrading PHP on Windows
You can then locate the PHPRC variable and edit it to point to the new PHP folder path. Note that you will need to close and reopen any CMD windows in order for them to detect the new Environment Variable paths.
🌐
Hows.tech
hows.tech › 2024 › 04 › how-to-update-php-version-using-cmd.html
How To Update Php Version Using Cmd
Click "New" and enter the path to your new PHP installation directory (e.g., "C:\php"). Click "OK" on all the open windows. ... Open a new CMD window and type php -v. If you see your new, shiny PHP version proudly displayed, then you, my friend, have conquered the command line! High fives all ...
🌐
Hongkiat
hongkiat.com › home › how to upgrade php to latest version
How to Upgrade PHP to Latest Version - Hongkiat
April 15, 2020 - With Homebrew, you can type the following command. ... The process may take a bit long, however, once it’s done you can run the php -v command again. You should now see that the version is updated:
Find elsewhere
🌐
DreamHost
help.dreamhost.com › hc › en-us › articles › 214202148-Change-the-PHP-version-the-shell-uses
Change the PHP version the shell uses – DreamHost Knowledge Base
If you’re using Tcsh, you must modify the lines as shown in the following before they can be added to the .tcshrc profile: alias php /usr/local/php84/bin/php set path=(/usr/local/php84/bin $path) You can also modify this accordingly using the path to any of the PHP-CLI binaries. The following sections explain how to use the .bash_profile to change the PHP version.
🌐
Bobcares
bobcares.com › blog › upgrade-php-on-windows
Upgrade PHP on Windows - Do it with ease
October 15, 2020 - We are now going to reuse all the values from the existing installation instead of starting from scratch. Once done, click the Cancel button. 9. Now from the FastCGI Settings window, click on Add Application… on the Actions pane on the right. ... C:\Program Files\PHP\v7.1\php-cgi.exe on the Full Path box. 11. Now enter all the values that you have copied from the Steps 8, except for the PHPRC where you want to update the value to 7.1 (i.e.,
Top answer
1 of 16
192

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 Windows icon

Step 2 - Click on the Settings icon

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 Path row and then click Edit

Step 9 - Click New and then click Browse, then in the next panel which will open you need to select the folder you want in the Path. For the initial premise of this guide i will add the folder C:\Users\NewFolderInPath

Note: Replace your PHP installed path(e.g:C:\Program Files\php) with the above path .

Step 10 - Click OK and click every OK button you will encounter to close every previous windows.

2 of 16
29

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

🌐
DEV Community
dev.to › xxzeroxx › how-to-update-php-in-linux-to-any-version-16mp
How to Update PHP in Linux to any version - DEV Community
January 13, 2024 - Replace Z.W with the version you want to enable (e.g., php8.2). ... Edit the Nginx configuration file (commonly /etc/nginx/sites-available/default) and update the fastcgi_pass directive to point to the new PHP-FPM version socket.
🌐
Infomaniak
infomaniak.com › en › support › faq › 2108 › change-the-php-version-in-cli
Change the PHP version in CLI
This guide explains how to change the PHP version used in the command line (PHP CLI) on an Infomaniak Web Hosting. PreambleThis guide is useful if you need...
🌐
Medium
medium.com › @kusuma844 › how-to-switch-your-php-version-in-windows-without-xampp-2776eed3de7
How to Switch your PHP Version in Windows (without XAMPP) | by Jayakusuma | Medium
July 27, 2022 - Okay, first, i assume you have your php folder on your C drive, or somewhere else. ... So, all that’s left is just installing the upgraded version of PHP, or rather i would say, placing the folder.
🌐
Codementor
codementor.io › community › switch php version on windows with one command
Switch php version on windows with one command | Codementor
December 6, 2024 - ), to switch your php version you need to type setx current_php [your_target_php_location] /m where [your_target_php_location] is the absolute path to the php version you want or use one of your php versions your defined here like this setx ...
🌐
GridPane
gridpane.com › kb › setting-the-cli-php-version
Setting the CLI PHP Version | GridPane
November 7, 2022 - For a few of you though, you may come across a situation where you need to change our defaults to a higher or lower version of PHP, and this article will walk you through how to make this change and set it so that our systems don’t automatically update it in the future.
🌐
YouTube
youtube.com › watch
How to Upgrade PHP on Windows - YouTube
In this video, we describe how to upgrade PHP on Windows.The related article for this article can be found here: https://www.liquidweb.com/kb/upgrading-php-w...
Published   December 29, 2017
🌐
Liquid Web
liquidweb.com › home › how to upgrade php on windows
How to Upgrade PHP on Windows | Liquid Web
February 18, 2025 - Type “PHP” in the Search Window at the top-right of the Web Platform Installer. Select the version of PHP that you wish to install and click “Add” and “Install”. Make sure to select the 64-bit or 32-bit, depending on your server ...
🌐
Medium
roman-academy.medium.com › how-to-update-php-version-in-ubuntu-linux-6d3934844938
How to update PHP version in Ubuntu Linux | by RomanAcademy | Medium
November 6, 2022 - You should see the latest PHP version shown in the terminal. If you’re using an Ubuntu computer, you can update the installed PHP by running the following commands: ... $ php -v PHP 8.1.2 (cli) (built: Apr 7 2022 17:46:26) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.2, Copyright (c) Zend Technologies with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies · If that doesn’t work, then you need to add the PPA repository created by Ondřej Surý to install the latest PHP version.