我正在尝试安装 PHP 扩展 PEAR,但我需要安装特定版本 7.3,以便与我将通过 Composer 安装的 PHP 应用程序兼容。
如果我这样做:
$ sudo apt-get install php-pear
Run Code Online (Sandbox Code Playgroud)
它安装得很好,问题是,它安装的是 7.4 版本。
Composer 告诉我我想要安装的应用程序需要 PEAR 7.3。
那么我就这样做:
$ sudo apt-get remove php-pear -y
$ sudo apt-get install php7.3-pear
Run Code Online (Sandbox Code Playgroud)
但我收到这个错误:
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'
Run Code Online (Sandbox Code Playgroud)
如何安装 PHP PEAR 7.3?谢谢你的帮助。
注意:这个答案试图回答OP的问题以及Erel遇到的导致赏金的类似问题。
首先,应该指出的是,除非您使用 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
Run Code Online (Sandbox Code Playgroud)
现在检查你的 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
Run Code Online (Sandbox Code Playgroud)
推荐的安装或修改 PEAR 的方法是with wget, not aptitude。所以你还需要wget安装。
sudo apt install wget
Run Code Online (Sandbox Code Playgroud)
现在获取go-pear.phar并确保命令解析并将响应保存到go-pear.phar本地。
wget http://pear.php.net/go-pear.phar
Run Code Online (Sandbox Code Playgroud)
然后用 PHP 运行该文件。
php go-pear.phar
Run Code Online (Sandbox Code Playgroud)
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:
Run Code Online (Sandbox Code Playgroud)
按下ENTER按键。注意:如果出现错误XML extension not found,请先安装 XML 模块(如果不使用 5.6,请确保版本号),然后重试。
sudo apt-get install php-xml php5.6-xml
Run Code Online (Sandbox Code Playgroud)
这是我观察到的输出。
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
Run Code Online (Sandbox Code Playgroud)
由于输出中出现警告,我选择手动编辑我的php.ini.
sudo nano /etc/php/5.6/cli/php.ini
Run Code Online (Sandbox Code Playgroud)
滚动到该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
Run Code Online (Sandbox Code Playgroud)
我取消注释该行;include_path = ".:/usr/share/php"并将其替换为include_path=".:/home/test/pear/share/pear"并重新启动 Apache。
sudo service apache2 restart
Run Code Online (Sandbox Code Playgroud)
要验证 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.
Run Code Online (Sandbox Code Playgroud)
参考:
编辑:
您遇到的一个重要问题是 php 和 php-pear 的版本号不同。
7.3 和 7.4 是 php 版本。php-pear 有类似 1.10.9 的版本。php7.3-pear除了实际包名称的任何可能变体之外,没有任何包。
请通读下面的整个答案,发布所需的信息,这将有助于评估您最终需要什么。 这可能会有所帮助。
首先列出可用版本
$ apt list -a <pkg>
$ apt-cache madison <pkg>
$ apt-cache policy <pkg>
$ apt show <pkg>
Run Code Online (Sandbox Code Playgroud)
(sudo不需要,与通常引用的相反)。如果您找到了所需的,请安装
$ sudo apt install <pkg>=<version>
Run Code Online (Sandbox Code Playgroud)
您可能还想使用标志-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
Run Code Online (Sandbox Code Playgroud)
正如预期的那样,这里也一样。要获得与软件包版本相关的进一步帮助,您应该发布以下输出
$ uname -a
$ lsb_release -a
$ dpkg -l | grep php
Run Code Online (Sandbox Code Playgroud)
如果您尝试运行的软件的编写方式只需要 PHP PEAR 7.3,那么您将不希望系统在裸机(或 VM)安装上运行,作为基础操作系统的未来更新可能会打破这个预期。相反,您可能需要考虑使用设置为使用 PHP 7.3 和匹配的 PEAR 库的 Docker 容器。
假设你已经安装了 Docker,你可以这样做:
docker pull php:7.3.33-apache
Run Code Online (Sandbox Code Playgroud)
然后你可以像这样配置你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/*
Run Code Online (Sandbox Code Playgroud)
最后rm将清除 apt 缓存并确保映像更小,以便于部署和可移植性。
您可以在此处阅读有关 PHP Docker 容器的更多信息。
使用 Docker 的好处在于,基础操作系统可以继续接收更新,而不会影响容器的稳定性。您还可以让容器在不同版本的 Ubuntu 上运行。例如,我的主要开发机器运行 21.10,而我的大多数生产服务器运行 20.04 LTS。
如果您以前从未使用过 Docker,那么将会有一个轻微的学习曲线。然而,一旦掌握了基础知识,您就会发现在尝试严格维护遗留(或公司)软件的版本要求时,它确实是唯一合乎逻辑的解决方案。
| 归档时间: |
|
| 查看次数: |
13496 次 |
| 最近记录: |