PHP:找不到“Phar”类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8851099/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP: Class 'Phar' not found
提问by SecStone
I try to use the Silex framework as base for my web application. However, if I try to include the *.phar archive, PHP throws the following error:
我尝试使用 Silex 框架作为我的 Web 应用程序的基础。但是,如果我尝试包含 *.phar 存档,PHP 会抛出以下错误:
Fatal error: Class 'Phar' not found in /var/www/framework/silex.phar on line 11
The following relevant lines are in my /etc/php/php.ini
(as suggested in the docs of Silex):
以下相关行在我的/etc/php/php.ini
(如 Silex 的文档中所建议):
extension=phar.so
phar.readonly = Off
phar.require_hash = Off
detect_unicode = Off
The PHAR library is present in /usr/lib/php/modules/phar.so
which is set as the extension path for all libraries in my php.ini
存在 PHAR 库,/usr/lib/php/modules/phar.so
其中设置为我的所有库的扩展路径php.ini
Does anyone know why PHP is throwing this error?
有谁知道为什么 PHP 会抛出这个错误?
采纳答案by George Cummins
Try specifying the path to the extension:
php -d extension=phar.so composer.phar <your_script>
Other options:
其他选项:
Based on the information you provided, there are a few possibilities:
根据您提供的信息,有以下几种可能:
You are using a different php.ini. Check the output of
phpinfo()
to confirm, and ensure that you are editing the active one./usr/lib/php/modules/phar.so is not readable. Ensure that the web server user can read this file.
Your web server has not been restarted since you last added the phar-related information to php.ini. Restart your webserver.
您正在使用不同的 php.ini。检查输出
phpinfo()
以确认,并确保您正在编辑活动的。/usr/lib/php/modules/phar.so 不可读。确保 Web 服务器用户可以读取此文件。
自从您上次将 phar 相关信息添加到 php.ini 后,您的 Web 服务器尚未重新启动。重新启动您的网络服务器。
回答by Indivision Dev
This works for me:
这对我有用:
php -d extension=phar.so composer.phar [... your command ...]
This includes the phar extension for the current runtime. Works for shared / VPC servers.
这包括当前运行时的 phar 扩展。适用于共享/VPC 服务器。
回答by chx
Hm. I think you need require_once 'phar://silex/silex.phar/autoload.php';
instead of require_once 'silex/silex.phar';
. If this is not the case then we need to see the code throwing an error.
嗯。我认为你需要require_once 'phar://silex/silex.phar/autoload.php';
而不是require_once 'silex/silex.phar';
. 如果不是这种情况,那么我们需要查看抛出错误的代码。
回答by Harry Bosh
in my hosting environment i needed to specify the php version number. EG:
在我的托管环境中,我需要指定 php 版本号。例如:
php-5.6 composer.phar
php-5.6 composer.phar
not
不是
php composer.phar
php作曲家.phar
回答by mmv_sat
Hope this may shed some light. I was using a shared host and had trouble getting composer to run. I was using this sites directions http://avantidevelopment.com/install-composer-on-bluehost/to setup a common directory and install composer in it. I followed it but shoud add for my alias I added the following command to .bashrc
希望这可能会有所启发。我正在使用共享主机并且无法运行 Composer。我正在使用这个网站的说明http://avantidevelopment.com/install-composer-on-bluehost/来设置一个公共目录并在其中安装 composer。我遵循了它,但应该为我的别名添加我将以下命令添加到 .bashrc
alias composer='/ramdisk/php/54/bin/php54-cli ~/common/composer.phar'
That did the trick for me. Hope whoever stumbles on this sets off a light bulb.
这对我有用。希望任何偶然发现的人都会点亮灯泡。
回答by Paul afk
For Mageia 4, Mageia 5, Mageia 6 users
适用于 Mageia 4、Mageia 5、Mageia 6 用户
>> urpmi php-phar;echo done To satisfy dependencies, the following packages are going to be installed: Package Version Release Arch (medium "Core Release2") php-bz2 5.6.30 2.mga6 x86_64 php-phar 5.6.30 2.mga6 x86_64 326KB of additional disk space will be used. 151KB of packages will be retrieved. Proceed with the installation of the 2 packages? (Y/n) y $MIRRORLIST: media/core/release/php-bz2-5.6.30-2.mga6.x86_64.rpm $MIRRORLIST: media/core/release/php-phar-5.6.30-2.mga6.x86_64.rpm installing php-phar-5.6.30-2.mga6.x86_64.rpm php-bz2-5.6.30-2.mga6.x86_64.rpm Preparing... ############################################### 1/2: php-bz2 ############################################### 2/2: php-phar ############################################### >>
回答by Martin Zeitler
On CentOS ...
在 CentOS 上...
phar.so
is contained in thephp-common
package.- the
phar
executable is contained in thephp-cli
package. php-mbstring
andphp-bz2
also seems to be required.
phar.so
包含在php-common
包中。- 该
phar
可执行文件包含在php-cli
包中。 php-mbstring
而且php-bz2
似乎也是必需的。
When php -m | grep phar
returns nothing, one has to add these .ini
files for the CLI:
当php -m | grep phar
什么都不返回时,必须.ini
为 CLI添加这些文件:
sudo cp /etc/php-zts.d/phar.ini /etc/php-cli.d/phar.ini
sudo cp /etc/php-zts.d/mbstring.ini /etc/php-cli.d/mbstring.ini
sudo cp /etc/php-zts.d/bz2.ini /etc/php-cli.d/bz2.ini
Alternatively, one can add the same module .ini
files as the webserver uses:
或者,可以添加与.ini
网络服务器使用相同的模块文件:
sudo cp /etc/php-zts.d/* /etc/php-cli.d/
It should look alike this:
它应该看起来像这样:
$ php --ini
Configuration File (php.ini) Path: /etc
Loaded Configuration File: /etc/php.ini
Scan for additional .ini files in: /etc/php-cli.d/
Additional .ini files parsed: /etc/php-cli.d/bz2.ini,
/etc/php-cli.d/mbstring.ini,
/etc/php-cli.d/phar.ini
Then one can run it:
然后可以运行它:
$ php ./composer.phar
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
And move it below the $PATH
:
并将其移至 下方$PATH
:
sudo mv ./composer.phar /usr/local/bin/composer