I want to install PHP 7.3 on Ubuntu 20.04 for my Nginx web server, when I try to install the 7.4 version everything is fine but for 7.3 I get the following error:

E: Unable to locate package php7.3

Then, I run the commands below:

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install -y php7.3

But, again, it shows that it can't locate the package. Does Ubuntu 20.04 support PHP 7.3 or below and if it does, what's wrong with my installation procedure?

4 Answers 4


Perhaps the support wasn't available when you asked the question but all you need to do is as described in your Q.

Add ondrej PPA repository to your system.

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

Install php7.3 and check it's installed.

sudo apt install -y php7.3
php -v

This also works for php 7.4, php7.2 and php5.6. Just change the relevant digits.

  • 1
    Nice repo, thanks for the link. Just installed PHP 7.0 on Ubuntu 20.04. Commented Aug 27, 2020 at 15:25
  • This solution is also valid for elementary OS 5.1 Hera. Commented Dec 26, 2020 at 15:52
  • @joe92 what do u mean by software-properties-common
    – Nasik Ahd
    Commented Aug 29, 2021 at 5:55

I got my problem solved for php7.2 but not sure about php7.3.

We can still install php7.2 by terminal: apt install php7.2.

But we have to install php7.4 too otherwise it will remove the main php package. It may need some research, but here are my instructions (for php7.2):

(sudo add-apt-repository ppa:ondrej/php won't be necessary, it can be removed)

  1. Install php7.2:

    sudo apt install php7.2
  2. Go to to this link and download the .deb file https://packages.ubuntu.com/bionic/amd64/libapache2-mod-php7.2/download (don't install it yet, we have to place it manually in the system)

  3. Extract libapache2. There will be a "data" archeive in it. It has two folders etc and usr. Copy those folders to matching directories of the root.

  4. Now to choose php7.2 rather than php7.4,because php7.4 is default, enter these commands

    sudo a2disconf php7.4-cgi 
    sudo a2dismod php7.4
    sudo a2enconf php7.2-cgi 
    sudo a2enmod php7.2
    sudo systemctl restart apache2
  5. Although php -v shows version 7.4 (because it's the latest), it still uses php7.2

  6. To switch from php7.4 to php7.2 older version:

    sudo update-alternatives --set php /usr/bin/php7.2
  7. Now php -v shows version 7.2 as default

It should now work as php7.2

  • 2
    you can't install any php lower than 7.4 on Ubuntu 20.04 via "apt install php7.2" you get an error: E: Unable to locate package php7.2 Commented Apr 28, 2020 at 18:13

Today I just realized that with the latest Ubuntu PPA update older PHP versions are available now.

So to install php7.3 or 7.2 just sudo apt update and you are ready to go!

  • 3
    This does not work for me. apt update; apt install php7.3 produces "E: Unable to locate package php7.3". Commented May 4, 2020 at 11:58

There seems to be something slightly off about the repository. I changed the /etc/apt/sources.list.d/ondrej-ubuntu-php-focal.list file for it and changed focal to eoan (19.10 Ubuntu version) and I can see all of the packages again.

I've installed using this but not tested any further.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .