35

I am trying to install PHP 7.4 on Ubuntu 16.04 for Apache2 server. To install the 7.4 version, I used PPA ondrej repository as follows:

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

I get the following error:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package php7.4
E: Couldn't find any package by glob 'php7.4'
E: Couldn't find any package by regex 'php7.4'

I tried all the solutions mentioned in answer to this question:

Unable to install PHP 7.3 on Ubuntu 20.04

None of them helped. How can I install this package?

Zanna
  • 205
  • 5
  • 13
Santosh Dangare
  • 685
  • 1
  • 4
  • 15
  • 1
    You might have better luck asking on askubuntu.com since this has to do with installing from repositories instead of being a coding issue. – aynber Jun 10 '21 at 12:09
  • yeah @aynber , but I thought SO has bigger community than askubantu.com that's why I aksed on SO – Santosh Dangare Jun 10 '21 at 12:15
  • 2
    sure it has a bigger community but the problem is, we only answer programming questions, not system setup questions. See [What topics can I ask about here?](https://stackoverflow.com/help/on-topic) . Each stackexchange community answers different types of questions. – ADyson Jun 10 '21 at 12:21
  • P.S. the link you've given refers to both a different version of PHP and a different version of Ubuntu. So there's going to be no guarantee it's applicable to your scenario. Ubuntu 16.04 just went out of support anyway so you should be upgrading the O/S, not the PHP version. – ADyson Jun 10 '21 at 12:24
  • @ADyson I also tried with `php 7.3` version but still not working – Santosh Dangare Jun 10 '21 at 12:25
  • yeah but it's a different O/S version too, as I already mentioned. Presumably the packages don't support 16.04 (which is perhaps unsurprising since 16.04 itself is also unsupported). Like I said...it's time to upgrade Ubuntu! – ADyson Jun 10 '21 at 12:27
  • @ADyson I was using `php 7.3` but i was facing problem to install `Xdebug` extension then I decided and tried to install `php 7.4` (so I removed `php 7.3`) now I am unable to install any of of them not even my previous version i.e. `php 7.3` – Santosh Dangare Jun 10 '21 at 12:39
  • 2
    That's unfortunate. But largely irrelevant...the bigger issue is running an unsupported O/S. Upgrade to a newer version and you should find that installing recent versions of PHP isn't an issue. – ADyson Jun 10 '21 at 12:42
  • But if you can remember how you installed 7.3 to begin with, it may be possible to re-install it the same way - the official repos for 16.04 haven't gone away (yet), although if you're using 3rd-party repos for this then there's less certainty - they often stop supporting an O/S at the same time Ubuntu does. It looks like that's probably what has happened here. https://ubuntu.com/about/release-cycle – ADyson Jun 10 '21 at 12:43
  • @ADyson now I don't remember how i install it in 16.04 – Santosh Dangare Jun 10 '21 at 12:51
  • As we keep saying then, it's time to upgrade your Ubuntu to a newer version. The table in the link I provided above shows you which versions are still supported. (Versions which are showing as currently being in Extended Security Maintenance (ESM) don't count because that's not standard support, you have to pay extra for it.) – ADyson Jun 10 '21 at 13:12

4 Answers4

29

You can archive this by adding this 3rd party repository to your system:

sudo add-apt-repository ppa:jczaplicki/xenial-php74-temp
sudo apt-get update

CAUTION:

This is adding an external PPA repository to your system. If you do not trust the maintainer you should not do this, since it possibly exposes your system. Also note that this might work for installing php, but there will not be a guarantee that you recvive updates through it (The word "temp" in the repository name indicates that this is only temporary). I would rather recommend compiling it yourself if you really need to have it installed on 16.04.

As a "Long-Term Solution" you really should update your system.

Tobias
  • 845
  • 10
  • 19
CGeorgian
  • 551
  • 6
  • 10
  • 4
    I'm not the downvoter, but code-only answers are generally not recommended; you should also provide an explanation of what the code does to solve the problem. When there are other answers it also helps to say why your answer is different or an improvement. – rmlockerd Aug 11 '21 at 04:54
  • Thank you! Is not the best solution but the ppa repo is okay to get out of the problem with you're lack of time. – maxirodr May 30 '22 at 05:37
  • Thanks for the answer. It helped me. Couldn't find it anywhere else. – Chris Nadovich Apr 15 '23 at 15:03
28

Your OS Ubuntu 16.04 (Xenial) is too old. Ondrej PPA only supports the following operating systems (as of 10 June 2021):

Hirsute (21.04), Groovy (20.10), Focal (20.04), Bionic (18.04)

Which is why there is no package found.

Tobias
  • 845
  • 10
  • 19
  • 1
    previously I had `php 7.3` which was working fine, but for some reason I need to install `7.4` so I remove `7.3`, and I failed to install `php 7.4` and also `php 7.3`. **Now I do not have any php version** – Santosh Dangare Jun 10 '21 at 12:46
  • 7
    Yes as said, your Operating system is not supported anymore. Ondrej PPA supports only versions of Ubuntu (and php) which are still supported. Standard Support for 16.04 ran out in April 2021, since then you probably did not get any php7.3 updates (Which by the way also runs out of support soon). You won't be able to install it via ondrej ppa again. But since your OS is outdated and out of support you really should update it. After updating your os to at least 18.04 you should be fine installing any php version >= 7.3 – Tobias Jun 10 '21 at 12:50
  • how can i install `php 7.3` even with 16.04 , is there any other option or repo to do that – Santosh Dangare Jun 10 '21 at 12:53
  • 2
    You can either compile it manually (There a lot of tutorials out there showing how), or you could also download the corresponding .deb packages and install them manually i guess. But keep in mind, that either of those ways you do not recive automatic security updates, etc. Again: A system upgrade should be done if possible. – Tobias Jun 10 '21 at 12:56
  • which are supported packages are there to install `php 7.3` or `7.4` in Ubantu `16.04` – Santosh Dangare Jun 11 '21 at 08:36
  • 3
    @Tobias you livesafer. I tested this out on different machines running 16.04 and none of them could find any PHP packages. After spending an entire day I stumbled upon this post. Thanks dude. – BRO_THOM Jun 15 '21 at 12:28
14

I ran into this recently. Luckily, I found a repo containing archives of the original Ondrej PPA. You will be able to install php7.4 and extensions. However, I'd be careful with any archives as they can have a security risk.

sudo add-apt-repository ppa:tomvlk/php-archive
sudo apt-get update
Thabo Moyo
  • 183
  • 1
  • 7
1

Here are installation instructions for ZendPHP repository - https://help.zend.com/zendphp/current/content/installation/installation.htm

The ZendPHP installation package replaces Ubuntu 16.04 distribution's PHP and supports PHP 5.6, PHP 7.1, PHP 7.2, PHP 7.3, and PHP 7.4 on Ubuntu 16.04. Zend also offers PHP LTS for versions that are EOL and no longer receiving high and critical security patches

  • Hi and welcome to SO. The link that you have posted might provide the answer, but it would be great if you could provide more details in your post in case the information in the link changes or if the link goes down – Simas Joneliunas Feb 12 '22 at 00:16
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/31047590) – SL ART Feb 17 '22 at 17:56
  • problem is that zend is a non-free source.. so you need to pay for access - which is ok if you are not able to upgrade your version - but you should note this. Also... support for 1604 has been removed.. – baradhili Mar 11 '22 at 02:20