24

I got this error when run below command

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

Reading state information... Done

E: Unable to locate package php7.2
E: Couldn't find any package by glob 'php7.2'
E: Couldn't find any package by regex 'php7.2'
E: Unable to locate package php7.2-common
E: Couldn't find any package by glob 'php7.2-common'
E: Couldn't find any package by regex 'php7.2-common'
E: Unable to locate package php7.2-cli
E: Couldn't find any package by glob 'php7.2-cli'
E: Couldn't find any package by regex 'php7.2-cli'
E: Unable to locate package php7.2-fpm
E: Couldn't find any package by glob 'php7.2-fpm'
E: Couldn't find any package by regex 'php7.2-fpm'
rawathemant
  • 744
  • 1
  • 4
  • 16

5 Answers5

48

You need to manually add the ondrej PPA to be able to install PHP7.2 on Ubuntu 17.

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.2

Or, by compiling it from the source by cloning the git repository, checking out the version that you want, make & make install

For more informations about compiling PHP from the source check out how to build/compile PHP from the source.

Mahmoud Abdelsattar
  • 1,299
  • 1
  • 15
  • 31
hassan
  • 7,812
  • 2
  • 25
  • 36
  • what's response that you are getting? and are you sure that the `apt-get update` command does not produce any errors/warngings? – hassan Jun 20 '18 at 12:18
  • May be issue with the ubuntu version. I did that installation successfully on ubuntu 16.04 but now i'm trying it on 17.04. – rawathemant Jun 20 '18 at 12:26
  • what is the response of executing `sudo apt-get install php7.2` ? – hassan Jun 20 '18 at 12:51
  • 1
    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' E: Couldn't find any package by regex 'php7.2' – rawathemant Jun 20 '18 at 13:05
  • what is the output of the following command : `grep -rn 'ondrej/php' /etc/apt/sources.list /etc/apt/sources.list.d/*` – hassan Jun 20 '18 at 13:45
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/173479/discussion-between-rawathemant-and-hassan). – rawathemant Jun 20 '18 at 13:46
  • I followed same step but still not installed.getting same error.I am getting error while update apt-get update. error like unable to find expected entry stable/source/sources . I am using ubuntu 17.04 and trying to install php7.3. getting error as unable to find package 7.3 – Dipti Mar 13 '19 at 07:31
  • @hassan I followed that command but still not installed. ubuntu@ip-172-31-13-22:~$ sudo apt-get 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 regex 'php7.2' ubuntu@ip-172-31-13-22:~$ – kuldeep May 21 '19 at 05:01
  • @kuldeep are you sure that you had added the repository successfully ? – hassan May 21 '19 at 15:07
  • @hassan I'am using VM with vagrant and I encounter the same problem after successful repository add and update. Here is the error that I get : vagrant@vagrant-ubuntu-trusty-64:~$ sudo apt-get install php7.3 Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package php7.3 E: Couldn't find any package by regex 'php7.3' – Mustapha GANGA Dec 27 '20 at 17:25
23

I had a similar problem. This page helped me resolve it. https://tecadmin.net/install-php-debian-9-stretch/

specifically, running these commands prior to the php install

sudo apt install ca-certificates apt-transport-https

wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -

echo "deb https://packages.sury.org/php/ stretch main" | sudo tee /etc/apt/sources.list.d/php.list

Roger Mungo
  • 361
  • 2
  • 6
0
  1. Completely remove ALL versions of PHP

    sudo apt-get purge 'php*' 
    
  2. Force update from unsigned repository:

    Add this option in your sources.list (located at /etc/apt/sources.list):

    deb [trusted=yes] https://deb.sury.org/ stretch main 
    
  3. Upgrade the current packages to the latest version:

    sudo apt update  
    
    sudo apt upgrade  
    
  4. Install the required packages first on your system:

    sudo apt install ca-certificates apt-transport-https  
    

    Then import packages signing key:

    wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -  
    

    After that configure PPA for the PHP packages on your system:

    echo "deb https://packages.sury.org/php/ stretch main" | sudo tee /etc/apt/sources.list.d/php.list 
    
  5. Lastly, use one of the below options to install PHP of your requirements:

    For installing PHP 7.2

    sudo apt install php7.2-cli 
    

    For installing PHP 7.1

    sudo apt install php7.1-cli 
    
Danziger
  • 19,628
  • 4
  • 53
  • 83
Hany Afifi
  • 67
  • 5
  • Why purge all existing php before updating? This is just asking for trouble. Install the new version and simply switch to using that instead. Remove old PHP once you are comfortably on the newer version. – Tisch Jan 29 '22 at 13:44
0

In my case a newer php was installed (7.4), so i just replaced the command with the 7.4 versions

sudo apt install php7.4 php7.4-common php7.4-cli php7.4-fpm

to know the version of php installed, use:

php --version
Dany Balian
  • 608
  • 7
  • 16
0

If you getting error like php7.2 php7.2-curl doesn't have installable candidate or not locate any package or dependencies is php7.2-common Or libcurl3 Do this . Remeber Change your package name as per your requirements

You have to tackle in mature way. Install aptitude these ubuntu package manager will finds all dependencies, and will install one by one.

apt-get install aptitude

Now you have to check if aptitude can download it or not if download it follow instructions

sudo aptitude install php7.2-curl

If you have gotten any error like this

E: Unable to locate package php7.2-curl
E: Couldn't find any package by glob 'php7.2-curl'

Any type on error i'm not talking about proper these errors

Try to add php package again

sudo apt-add-repository ppa:ondrej/php

sudo apt-get update

Now try this command

sudo aptitude install php7.2-curl

Aptitude will ask you you want to keep current version of all dependencies

The following actions will resolve these dependencies:

     Keep the following packages at their current version:
1)     php7.2-curl [Not Installed]                        



Accept this solution? [Y/n/q/?]

Type n then Enter

Aptitude will find all dependencies and ask you to install all package type

y

Again

y

Then

systemctl restart apache2

For centos of rhel

systemctl restart httpd

It will Not enabling PHP 7.2 FPM by default. NOTICE: To enable PHP 7.2 FPM in Apache2 do

a2enmod proxy_fcgi setenvif

a2enconf php7.2-fpm

This method is not only for this error you can find any of php apache2 or ubuntu system package solution using aptitude.

Upvote if you find your solution
Ronny Dsouza
  • 358
  • 2
  • 12