Question

Unable to locate package php7.2 Ubuntu 20.04

Posted November 10, 2021 407 views
ApachePHPDigitalOceanPHP FrameworksUbuntu 20.04

We are unable to install the php7.2 and php7.1 version in the ubuntu 20.04.
Currently we are using php7.4 and we need the php7.2 also

When we tried to install the php7.2 below commands were not successful in the digital ocean.

downgrade PHP version to 7.2

apt install php7.2

Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package php7.2
E: Couldn’t find any package by glob ‘php7.2’

sudo apt-add-repository ppa:ondrej/php

sudo apt update

sudo apt install -y php7.2 php7.2-cli php7.2-common php7.2-fpm

sudo apt install -y php7.2-mysql php7.2-dom php7.2-simplexml php7.2-ssh2 php7.2-xml php7.2-xmlreader php7.2-curl  php7.2-exif  php7.2-ftp php7.2-gd  php7.2-iconv php7.2-imagick php7.2-json  php7.2-mbstring php7.2-posix php7.2-sockets php7.2-tokenizer

sudo apt install -y php7.2-mysqli php7.2-pdo  php7.2-sqlite3 php7.2-ctype php7.2-fileinfo php7.2-zip php7.2-exif

Let us know the solutions for this asap.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
2 answers

Hello,

I just tested this on a fresh new Ubuntu 20.04 Droplet and I was able to install PHP 7.2 after running the following commands:

  • Update your repositories:
sudo apt update
  • Then add the Ondrej PHP repository:
sudo apt-add-repository ppa:ondrej/php
  • Run apt update again:
sudo apt update
  • Finally install PHP 7.2:
sudo apt install -y php7.2 php7.2-cli php7.2-common php7.2-fpm

If it still does not work, can you share the output of the following command here:

grep -rn 'ondrej/php' /etc/apt/sources.list /etc/apt/sources.list.d/*

Let me know how it goes!
Best,
Bobby

  • @bobbyiliev Please find the below message and commands output

    root@ubuntu-s-1vcpu-2gb-blr1-01:~# sudo apt install -y php7.2 php7.2-cli php7.2-common php7.2-fpm
    
    ```Reading package lists... Done
    
    Building dependency tree
    Reading state information... Done
    Package php7.2-common is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source
    
    E: Unable to locate package php7.2
    E: Couldn't find any package by glob 'php7.2'
    E: Unable to locate package php7.2-cli
    E: Couldn't find any package by glob 'php7.2-cli'
    E: Package 'php7.2-common' has no installation candidate
    E: Unable to locate package php7.2-fpm
    E: Couldn't find any package by glob 'php7.2-fpm'
    
    
    ```root@ubuntu-s-1vcpu-2gb-blr1-01:~# grep -rn 'ondrej/php' ```/etc/apt/sources.list /etc/apt/sources.list.d/*
    /etc/apt/sources.list.d/ondrej-ubuntu-php-groovy.list:1:deb http://ppa.launchpad.net/ondrej/php/ubuntu/ groovy main
    /etc/apt/sources.list.d/ondrej-ubuntu-php-groovy.list:2:# deb-src http://ppa.launchpad.net/ondrej/php/ubuntu/ groovy main
    
    • Hello,

      As far as I can see you are using the Ondrej repository for Ubuntu Groovy(20.10), however, you mentioned that your Ubuntu version is 20.04 (Hirsute Hippo).

      To verify that you are running Ubuntu 20.04, run the following command:

      cat /etc/os-release 
      

      If this is the case, you need to add the correct repository by doing the following:

      • Create this file:
      /etc/apt/sources.list.d/ondrej-ubuntu-php-hirsute.list
      
      • And add the following content:
      deb http://ppa.launchpad.net/ondrej/php/ubuntu/ hirsute main
      # deb-src http://ppa.launchpad.net/ondrej/php/ubuntu/ hirsute main
      

      After that run sudo apt update and try to install PHP 7.2 again.

      Let me know how it goes.
      Best,
      Bobby

      • I have done with given commands and still some thing different @bobbyiliev

        Could you please check the below error once

        sudo apt-get install php7.2
        

        Reading package lists… Done
        Building dependency tree
        Reading state information… Done
        Some packages could not be installed. This may mean that you have
        requested an impossible situation or if you are using the unstable
        distribution that some required packages have not yet been created
        or been moved out of Incoming.
        The following information may help to resolve the situation:

        The following packages have unmet dependencies:
        php7.2 : Depends: libapache2-mod-php7.2 but it is not installable or
        php7.2-fpm but it is not installable or
        php7.2-cgi but it is not installable
        php7.2-common : Depends: libc6 (>= 2.33) but 2.32-0ubuntu3 is to be installed
        E: Unable to correct problems, you have held broken packages.

        Here is the error

      • cat /etc/os-release
        

        NAME=“Ubuntu”
        VERSION=“20.10 (Groovy Gorilla)”
        ID=ubuntu
        IDLIKE=debian
        PRETTY
        NAME=“Ubuntu 20.10”
        VERSIONID=“20.10”
        HOME
        URL=“https://www.ubuntu.com/
        SUPPORTURL=“https://help.ubuntu.com/
        BUG
        REPORTURL=“https://bugs.launchpad.net/ubuntu/
        PRIVACY
        POLICYURL=“https://www.ubuntu.com/legal/terms-and-policies/privacy-policy
        VERSION
        CODENAME=groovy
        UBUNTU_CODENAME=groovy

        • Hi there,

          As you are using Ubuntu Groovy, you should not add the Ubuntu Hirsute repository. I would recommend reverting that change.

          Going through the available PHP 7.2 packages on the repository here:

          http://ppa.launchpad.net/ondrej/php/ubuntu/pool/main/p/php7.2/

          It looks like that php7.2-fpm is not available for Ubuntu 20.10 which is your current version.

          I could suggest either upgrading to ubuntu 21.04. Or deploying a new Droplet with an older version instead so that you could get that package.

          Let me know how it goes.

          Best,
          Bobby

It looks like that php7.2-fpm is not available for Ubuntu 20.10

As per the @bobbyiliev suggestion i have created the new droplets and configured ubuntu 21.04 with php7.2 without any issues.

Thanks @bobbyiliev for your support.