我正在尝试安装 PHP 扩展 PEAR,但我需要安装特定版本 7.3,以便与我将通过 Composer 安装的 PHP 应用程序兼容。
如果我这样做:
$ sudo apt-get install php-pear
安装很好,问题是,它安装的是 7.4 版本。
Composer 告诉我我想要安装的应用程序需要 PEAR 7.3。
因此我这样做:
$ sudo apt-get remove php-pear -y
$ sudo apt-get install php7.3-pear
但是我收到此错误:
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'
如何安装 PHP PEAR 7.3?感谢您的帮助。
答案1
注意:这个答案试图回答OP的问题以及类似的问题埃雷尔正在获得赏金。
首先,应该指出的是,除非您使用编译的 PHP./configure flag --without-pear
或您正在运行的 PHP 4.2.* 或更早版本,你应该已经安装了 PEAR 的基本版本,它应该已经包含安装 PEAR 包所需的一切。
我的其余回答假设 PEAR 未默认安装或配置错误。无论哪种方式,以下是我手动安装它的方法。
注意:如果您在本地安装了多个版本的 PHP,并且没有使用 VM 或 Docker,请记住先切换 PHP 版本。例如,我通常使用 PHP 7.4,但想使用 5.6 进行重现,所以我必须运行以下命令。
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
现在检查你的 PHP 版本php -v
,它应该输出类似这样的内容。
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
这安装或修改 PEAR 的推荐方法是wget
,不是aptitude
。因此您还需要wget
安装。
sudo apt install wget
现在获取go-pear.phar
并确保命令解析且响应保存到go-pear.phar
本地。
wget http://pear.php.net/go-pear.phar
然后使用 PHP 运行该文件。
php go-pear.phar
PHP 将为您的新 PEAR 安装建议默认设置,这对于大多数用例来说应该完全没问题。
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:
按下该ENTER
键。注意:如果出现错误XML extension not found
,首先安装 XML 模块(如果不是使用 5.6,请确保版本号)并重试。
sudo apt-get install php-xml php5.6-xml
这是我观察到的输出。
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
由于输出中的警告,我选择手动编辑我的php.ini
。
sudo nano /etc/php/5.6/cli/php.ini
滚动到该Paths and Directories
部分。
;;;;;;;;;;;;;;;;;;;;;;;;;
; 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
我取消了该行的注释;include_path = ".:/usr/share/php"
并将其替换为include_path=".:/home/test/pear/share/pear"
,然后重新启动 Apache。
sudo service apache2 restart
要验证 PEAR 是否正常工作,只需在命令行中输入 pear。我的最终输出如下所示。
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.
答案2
编辑:
您遇到的一个基本问题是 php 和 php-pear 的版本号不同。
php7.3-pear
7.3 和 7.4 是 php 版本。php-pear 有类似 1.10.9 的版本。除了实际包名称的任何可能变体之外,没有包。
请通读下面的整个答案,发布所需的信息,这将有助于评估您最终需要什么。 这可能会有帮助。
首先列出可用的版本
$ apt list -a <pkg>
$ apt-cache madison <pkg>
$ apt-cache policy <pkg>
$ apt show <pkg>
(sudo
不需要,与通常引用的相反)。如果你找到了你需要的,安装
$ sudo apt install <pkg>=<version>
您可能还想使用标志-s
来模拟该过程并检查是否存在任何问题. 或者标记-V
以显示详细输出。
奇怪的是,我看到的数字与你引用的数字完全不同
$ 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
和相同的这里,正如预期的那样。要获取与软件包版本相关的进一步帮助,您应该发布
$ uname -a
$ lsb_release -a
$ dpkg -l | grep php
答案3
如果您尝试运行的软件仅需要 PHP PEAR 7.3,那么您不会希望在裸机(或虚拟机)安装上运行系统,因为未来对基础操作系统的更新可能会破坏这一预期。相反,您可能希望使用设置为使用 PHP 7.3 和匹配的 PEAR 库的 Docker 容器。
假设您已经安装了 Docker,您可以执行以下操作:
docker pull php:7.3.33-apache
Dockerfile
然后你可以像这样配置:
FROM php/7.3.33-apache:latest
WORKDIR "/var/www"
RUN apt-get update; \
apt-get install -y php-pear; \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
最后rm
将清除 apt 缓存并确保图像更小,以便于部署和运输。
你可以点击此处了解有关 PHP Docker 容器的更多信息。
使用 Docker 的好处在于,基础操作系统可以继续接收更新,而不会影响容器的稳定性。您还可以让容器在不同版本的 Ubuntu 上运行。例如,我的主要开发机器运行 21.10,而我的大多数生产服务器运行 20.04 LTS。
如果您以前从未使用过 Docker,那么学习起来会有些困难。但是,一旦您掌握了基础知识,您就会发现,当您试图严格遵守旧版(或企业)软件的版本要求时,这确实是唯一合理的解决方案。