How to install a specific version of PEAR (the PHP extension)?

I'm trying to install the PHP extension, PEAR, but I need to install a specific version, 7.3, in order to be compatible with a PHP app I'm going to be installing via Composer.

If I do this:

$ sudo apt-get install php-pear

It installs fine, the problem is, it installs version 7.4.

Composer is telling me the app I want to installs requires PEAR 7.3.

So then I do this:

$ sudo apt-get remove php-pear -y
$ sudo apt-get install php7.3-pear

But I get this error:

E: Unable to locate package php7.3-pear
E: Couldn't find any package by glob 'php7.3-pear'
E: Couldn't find any package by regex 'php7.3-pear'

How can I install PHP PEAR 7.3? Thanks for any help.


NOTE: This answer attempts to answer the OP's question as well as the similar problem Erel is having which prompted the bounty.

Firstly, it should be pointed out that unless you have compiled your PHP with the ./configure flag --without-pear or you are running you are running PHP 4.2.* or earlier, you should already have a base installation of PEAR, and it should already contain everything needed to install PEAR packages.

The rest of my answer assumes PEAR was either not installed by default or was misconfigured. Either way, here is how I installed it manually.

Note: If you have multiple versions of PHP installed locally and are not using a VM or Docker, remember to first switch PHP versions. For example, I normally use PHP 7.4 but wanted to reproduce using 5.6, so I had to run the following.

sudo a2dismod php7.4
sudo a2enmod php5.6
sudo service apache2 restart

sudo update-alternatives --set php /usr/bin/php5.6
sudo update-alternatives --set phar /usr/bin/phar5.6
sudo update-alternatives --set phar.phar /usr/bin/phar.phar5.6
# If you have php5.6-dev installed as well
sudo update-alternatives --set phpize /usr/bin/phpize5.6
sudo update-alternatives --set php-config /usr/bin/php-config5.6

Now check your PHP version php -v and it should output something like this.

PHP 5.6.40-57+ubuntu20.04.1+deb.sury.org+1 (cli)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies with Zend 
OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

The recommended method of installing or modifying PEAR is with wget, not aptitude. So you also need to have wget installed.

sudo apt install wget

Now acquire go-pear.phar and ensure the command resolves and the response is saved to go-pear.phar locally.

wget http://pear.php.net/go-pear.phar

And then run the file with PHP.

php go-pear.phar

PHP will suggest the defaults for your new PEAR installation, which should be perfectly fine for most use cases.

Below is a suggested file layout for your new PEAR installation. To
change individual locations, type the number in front of the
directory.  Type 'all' to change all of them or simply press Enter to
accept these locations.

1. Installation base ($prefix)               : /home/test/pear
2. Temporary directory for processing        : /tmp/pear/install
3. Temporary directory for downloads         : /tmp/pear/install
4. Binaries directory                        : /home/test/pear/bin
5. PHP code directory ($php_dir)             : /home/test/pear/share/pear
6. Documentation directory                   : /home/test/pear/docs
7. Data directory                            : /home/test/pear/data
8. User-modifiable config files directory    : /home/test/pear/cfg
9. Public Web Files directory                : /home/test/pear/www
10. System manual pages directory            : /home/test/pear/man
11. Tests directory                          : /home/test/pear/tests
12. Name of configuration file               : /home/test/.pearrc

1-12, 'all' or Enter to continue:

Hit the ENTER key. Note: If you get an error XML extension not found, first install the XML module (be sure the version number if not using 5.6) and try again.

sudo apt-get install php-xml php5.6-xml

Here is the output I observed.

Beginning install...
Configuration written to /home/test/.pearrc...
Initialized registry...
Preparing to install...
installing phar:///home/test/go-pear.phar/PEAR/go-pear-tarballs/Archive_Tar-1.4.14.tar...
installing phar:///home/test/go-pear.phar/PEAR/go-pear-tarballs/Console_Getopt-1.4.3.tar...
installing phar:///home/test/go-pear.phar/PEAR/go-pear-tarballs/PEAR-1.10.13.tar...
installing phar:///home/test/go-pear.phar/PEAR/go-pear-tarballs/Structures_Graph-1.1.1.tar...
installing phar:///home/test/go-pear.phar/PEAR/go-pear-tarballs/XML_Util-1.4.5.tar...
install ok: channel://pear.php.net/Archive_Tar-1.4.14
install ok: channel://pear.php.net/Console_Getopt-1.4.3
install ok: channel://pear.php.net/Structures_Graph-1.1.1
install ok: channel://pear.php.net/XML_Util-1.4.5
install ok: channel://pear.php.net/PEAR-1.10.13
PEAR: Optional feature webinstaller available (PEAR's web-based installer)
PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer)
PEAR: To install optional features use "pear install pear/PEAR#featurename"
******************************************************************************
WARNING! The include_path defined in the currently used php.ini does not contain the PEAR PHP directory you just specified:
</home/test/pear/share/pear>
If the specified directory is also not in the include_path used by your scripts, you will have problems getting any PEAR packages working.

Would you like to alter php.ini </etc/php/5.6/cli/php.ini>? [Y/n] : y

******************************************************************************
WARNING: Cannot write to /etc/php/5.6/cli/php.ini, but php.ini was successfully created at </home/test/pear/php.ini-gopear>. Please replace the file </etc/php/5.6/cli/php.ini> with </home/test/pear/php.ini-gopear> or modify your php.ini by adding:

include_path=".:/home/test/pear/share/pear"

Current include path           : .:/usr/share/php
Configured directory           : /home/test/pear/share/pear
Currently used php.ini (guess) : /etc/php/5.6/cli/php.ini
Press Enter to continue:

** WARNING! Old version found at /usr/bin/pear, please remove it or be sure 
to use the new /home/test/pear/bin/pear command

The 'pear' command is now at your service at /home/test/pear/bin/pear

Because of the warning in the output, I opted to manually edit my php.ini.

sudo nano /etc/php/5.6/cli/php.ini

Scroll to the Paths and Directories section.

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
;include_path = ".:/usr/share/php"
;
; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"
;
; PHP's default setting for include_path is ".;/path/to/php/pear"
; http://php.net/include-path

I uncommented the line ;include_path = ".:/usr/share/php" and replaced it with include_path=".:/home/test/pear/share/pear" and restarted Apache.

sudo service apache2 restart

To verify PEAR is working, simply type pear on the command line. My final output is shown below.

test@REDQUEEN1:~$ pear
Commands:
build                  Build an Extension From C Source
bundle                 Unpacks a Pecl Package
channel-add            Add a Channel
channel-alias          Specify an alias to a channel name
channel-delete         Remove a Channel From the List
channel-discover       Initialize a Channel from its server
channel-info           Retrieve Information on a Channel
channel-login          Connects and authenticates to remote channel server
channel-logout         Logs out from the remote channel server
channel-update         Update an Existing Channel
clear-cache            Clear Web Services Cache
config-create          Create a Default configuration file
config-get             Show One Setting
config-help            Show Information About Setting
config-set             Change Setting
config-show            Show All Settings
convert                Convert a package.xml 1.0 to package.xml 2.0 format
cvsdiff                Run a "cvs diff" for all files in a package
cvstag                 Set CVS Release Tag
download               Download Package
download-all           Downloads each available package from the default channel
info                   Display information about a package
install                Install Package
list                   List Installed Packages In The Default Channel
list-all               List All Packages
list-channels          List Available Channels
list-files             List Files In Installed Package
list-upgrades          List Available Upgrades
login                  Connects and authenticates to remote server [Deprecated in favor of channel-login]
logout                 Logs out from the remote server [Deprecated in favor of channel-logout]
makerpm                Builds an RPM spec file from a PEAR package
package                Build Package
package-dependencies   Show package dependencies
package-validate       Validate Package Consistency
pickle                 Build PECL Package
remote-info            Information About Remote Packages
remote-list            List Remote Packages
run-scripts            Run Post-Install Scripts bundled with a package
run-tests              Run Regression Tests
search                 Search remote package database
shell-test             Shell Script Test
sign                   Sign a package distribution file
svntag                 Set SVN Release Tag
uninstall              Un-install Package
update-channels        Update the Channel List
upgrade                Upgrade Package
upgrade-all            Upgrade All Packages [Deprecated in favor of calling upgrade with no parameters]
Usage: pear [options] command [command-options] <parameters>
Type "pear help options" to list all options.
Type "pear help shortcuts" to list all command shortcuts.
Type "pear help version" or "pear version" to list version information.
Type "pear help <command>" to get the help for the specified command.

👍

References:

  • PEAR Manual
  • Serverfault SE
  • Dreamhost's PEAR Installation Guide

EDIT:

An essential problem you are suffering is that version numbers of php and php-pear are different.

7.3 and 7.4 are php versions. php-pear has something like 1.10.9. There is no package php7.3-pear, beyond any possible variations of the actual package name.

Please read through the whole answer below, post the requested info, and that will help assessing what you ultimately need. This may help.


First list available versions with either of

$ apt list -a <pkg>
$ apt-cache madison <pkg>
$ apt-cache policy <pkg>
$ apt show <pkg>

(sudo is not needed, as opposite what is usually quoted). If you found the one you need, install with

$ sudo apt install <pkg>=<version>

see 1. Note you may want to append a wildcard \*.

You may also want to use flag -s to simulate the process and check for any issues. Or flag -V for a verbose output.

The strange thing is that I am seeing a numbering completely different from what you quote

$ sudo apt list -a php-pear
Listing... Done
php-pear/focal-updates,focal-updates,focal-security,focal-security 1:1.10.9+submodules+notgz-1ubuntu0.20.04.3 all
php-pear/focal,focal 1:1.10.9+submodules+notgz-1 all

and the same here, as expected. To get further help related to package versions, you should post the output of

$ uname -a
$ lsb_release -a
$ dpkg -l | grep php