简体   繁体   English

如何在 Ubuntu 上安装 Phar?

[英]How to install Phar on Ubuntu?

I got into a situation where if I run composer install on my PHP project, I get this error:我遇到了一种情况,如果我在我的 PHP 项目上运行composer install ,我会收到这个错误:

Fatal error: Class 'Phar' not found in /usr/local/bin/composer on line 23

As I read composer update class phar not found , I tried to check if Phar was installed by doing php -i | grep 'phar'当我读到composer update class phar not found 时,我尝试通过执行php -i | grep 'phar'检查是否安装了 Phar php -i | grep 'phar' php -i | grep 'phar' , and Phar is not installed. php -i | grep 'phar' ,并且未安装 Phar。

I am using PHP 5.6.我正在使用 PHP 5.6。

How can I install Phar on Ubuntu please?请问如何在 Ubuntu 上安装 Phar?

[EDIT] When I try apt-get install php-phar , I get: [编辑] 当我尝试apt-get install php-phar ,我得到:

Package php-phar is a virtual package provided by:
  php7.2-common 7.2.7-1+ubuntu14.04.1+deb.sury.org+1
  php7.1-common 7.1.19-1+ubuntu14.04.1+deb.sury.org+1
  php5.6-common 5.6.36-1+ubuntu14.04.1+deb.sury.org+1
  php7.0-common 7.0.30-1+ubuntu14.04.1+deb.sury.org+1
You should explicitly select one to install.

Then, if I try apt-get install php5.6-common :然后,如果我尝试apt-get install php5.6-common

php5.6-common is already the newest version.
php5.6-common set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 295 not upgraded.

Try to run php -i|grep phar尝试运行php -i|grep phar

If it shows result something like :如果它显示结果类似于:

/etc/php/{version}/cli/conf.d/20-phar.ini,
Registered PHP Streams => https, ftps, compress.zlib, php, file, glob, data, http, ftp, compress.bzip2, phar, zip
Phar-based phar archives => enabled
Tar-based phar archives => enabled
ZIP-based phar archives => enabled
phar.cache_list => no value => no value
phar.readonly => On => On
phar.require_hash => On => On

Everything should be correctly installed.一切都应该正确安装。

If it shows no result or no phar ini files mentioned / disabled then you just need to include the correct ini on your main php.ini and set the path to phar.so files.如果它没有显示任何结果或没有提到/禁用 phar ini 文件,那么您只需要在主 php.ini 中包含正确的 ini 并设置phar.so文件的路径。

or if you locate the phar.so file just add it on your main php.ini with或者,如果您找到 phar.so 文件,只需将其添加到您的主 php.ini 中

extension=phar.so

or或者

extension=path/to/your/phar.so

Update + extra to ensure ext dir location更新 + 额外以确保 ext 目录位置

It will be clearer if you grasp ini file location and ext dir used by your installation.如果您掌握了安装使用的 ini 文件位置和 ext 目录,则会更清楚。

Try to do this: php -i | grep ini尝试这样做: php -i | grep ini php -i | grep ini

Then on the first/second line there will be your main ini file.然后在第一行/第二行会有你的主 ini 文件。

In my machine it shows this: Loaded Configuration File => /etc/php/{version}/cli/php.ini在我的机器上它显示了这个: Loaded Configuration File => /etc/php/{version}/cli/php.ini

then do this command to make sure ext folder used or any extension declared on main ini: cat /etc/php/{version}/cli/php.ini|grep ext然后执行此命令以确保使用 ext 文件夹或在主 ini 上声明的任何扩展名: cat /etc/php/{version}/cli/php.ini|grep ext

You could also do:你也可以这样做:

cat /etc/php/{version}/cli/php.ini|grep phar

To check phar related parameter on main ini file.检查主 ini 文件上的 phar 相关参数。

If those step show nothing, I think it will be simpler if you just reinstall your php package on your machine.如果这些步骤什么也没显示,我认为如果您在机器上重新安装 php 包会更简单。

You have to install the extension first with:您必须先安装扩展程序:

apt install php-phar

normally it should register the extension automatically and it should work.通常它应该自动注册扩展并且它应该可以工作。

If php5 doesn't recognize the phar.so lib, try to update to 7.x如果php5不能识别phar.so库,尝试更新到7.x

The phar lib is auto included in newer packages and will be automatically configured as well. phar 库自动包含在较新的软件包中,并且也会自动配置。 Hope that can help希望能帮上忙

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM