php 需要 ext-fileinfo。如何将其添加到我的 composer.json 文件中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23771117/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:55:30  来源:igfitidea点击:

requires ext-fileinfo. How do I add that into my composer.json file?

phplaravelcomposer-php

提问by Monica

I am trying to install intervention/image. After running the composer update, I get:

我正在尝试安装干预/图像。运行作曲家更新后,我得到:

enter image description here

在此处输入图片说明

This is my composer file:

这是我的作曲家文件:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "laravel/framework": "4.1.*",
        "intervention/image": "2.*"
    },
    "autoload": {
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/models",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    },
    "minimum-stability": "stable"
}

回答by Alexandru Guzinschi

Nothing to do with your composer.json.

与您的 composer.json 无关。

You need to install & enable FileInfo PHP extension, which is installed by default starting with PHP 5.3.0. Versions prior to 5.3+ may use the discontinued PECL extension.

您需要安装并启用 FileInfo PHP 扩展,从 PHP 5.3.0 开始默认安装。5.3+ 之前的版本可能使用已停产的 PECL 扩展

To enable FileInfo extension, you need to edit your php.ini and change a single line.

要启用 FileInfo 扩展,您需要编辑 php.ini 并更改一行。

  1. Locate the line:

    ;extension=php_fileinfo.dll
    
  2. Remove the starting comment:

    extension=php_fileinfo.dll
    
  1. 找到该行:

    ;extension=php_fileinfo.dll
    
  2. 删除起始注释:

    extension=php_fileinfo.dll
    


To find out where your php.ini is located, you can run the following command from a terminal:

要找出 php.ini 所在的位置,您可以从终端运行以下命令:

$ php --ini

and search for "Loaded Configuration File".

并搜索“加载的配置文件”。

Please notethat the PHP CLI can load a different php.ini file than the web, so don't rely on the path provided in phpinfo(). Run the command specified above in a terminal to find out the file loaded by PHP CLI.

请注意,PHP CLI 可以加载与 Web 不同的 php.ini 文件,因此不要依赖 .ini 文件中提供的路径phpinfo()。在终端中运行上面指定的命令以查找 PHP CLI 加载的文件。

回答by sumit

We dont need to do anything in composer.json

我们不需要在 composer.json 中做任何事情

Windows

视窗

Enable fileinfo extension in php.ini

php.ini 中启用文件信息扩展

extension= php_fileinfo.dll

In Linux

在 Linux 中

1) Download and untar the package

1) 下载并解压包

wget http://pecl.php.net/get/Fileinfo-1.0.4.tgz

wget http://pecl.php.net/get/Fileinfo-1.0.4.tgz

tar -zxf Fileinfo-1.0.4.tgz

tar -zxf 文件信息-1.0.4.tgz

cd Fileinfo-1.0.4

cd Fileinfo-1.0.4

2) Generate the extension for compiling

2) 生成编译用的扩展名

phpize

phpize

3) Configure the module

3) 配置模块

./configure

。/配置

4) generate the install files and install it

4) 生成安装文件并安装

make

制作

make install

进行安装

5) Now the extension will be available under the /usr/lib64/php/modules directory. You now need to add the extension somewhere in the php configuration file. Edit /etc/php.ini and add the following: extension=fileinfo.so 6) Save the file and restart the webserver

5) 现在扩展将在 /usr/lib64/php/modules 目录下可用。您现在需要在 php 配置文件中的某处添加扩展名。编辑 /etc/php.ini 并添加以下内容: extension=fileinfo.so 6) 保存文件并重新启动网络服务器

service httpd restart

服务 httpd 重启

To verify fileinfo module is enabled properly, execute:

要验证文件信息模块是否正确启用,请执行:

php -i | grep fileinfo

php -i | grep 文件信息

fileinfo support => enabled

文件信息支持 => 启用

Alternate method

替代方法

Just an FYI, the module can also be installed using the PECL command i.e.

仅供参考,该模块也可以使用 PECL 命令安装,即

pecl install fileinfo

pecl 安装文件信息

Once done, just follow steps 5 and 6 mentioned above to enable it. That's it.

完成后,只需按照上面提到的步骤 5 和 6 启用它。就是这样。

回答by Jake Bathman

If anyone else is on DreamHost (like me) or finds that the php.ini edits don't do what you want, you can try another route.

如果其他人在 DreamHost 上(像我一样)或发现 php.ini 编辑不符合您的要求,您可以尝试另一条路线。

Here's the DreamHost Wiki page on PHP.ini, but I'll list the steps below as well.

这是 PHP.ini 上的 DreamHost Wiki 页面,但我也会列出以下步骤。

Step 1: Create a PHP configuration file (phprc)

第一步:创建PHP配置文件(phprc)

  1. In your user's home folder (/home/your_user_name), create a new folder called .php(notice the leading period)
  2. Inside this new folder, create another folder based on the version of PHP that you're using. You can find this (and change it) on the hosting panel (DreamHost's is at panel.dreamhost.comunder Domains > Manage Domains). So if you're using PHP version 5.6, create a folder called 5.6.
  3. Inside this new folder, create a new file called phprc(no extension). If there's already a phprcfile in this folder, you can back it up by changing the filename to phprc.old.
  1. 在您用户的主文件夹 ( /home/your_user_name) 中,创建一个名为.php(注意前导句点)的新文件夹
  2. 在这个新文件夹中,根据您使用的 PHP 版本创建另一个文件夹。您可以在主机面板上找到(并更改它)(DreamHost 位于panel.dreamhost.com下的域 > 管理域)。因此,如果您使用的是 PHP 5.6 版,请创建一个名为5.6.
  3. 在这个新文件夹中,创建一个名为phprc(无扩展名)的新文件。如果phprc此文件夹中已经有文件,您可以通过将文件名更改为phprc.old.

Step 2: Edit phprcto include the extension

第 2 步:编辑phprc以包含扩展名

  1. Open your new phprcfile.
  2. Add this line to the end: extension = fileinfo.so
  3. Save the file
  1. 打开你的新phprc文件。
  2. 将此行添加到末尾: extension = fileinfo.so
  3. 保存文件

Step 3: Restart PHP and/or your web server

第 3 步:重新启动 PHP 和/或您的 Web 服务器

通过面板

If you have shared hosting, or you aren't comfortable with SSH or the command line, you can force DreamHost to pick up your new phprcsettings.

如果您有共享主机,或者您对 SSH 或命令行不满意,您可以强制 DreamHost 选择您的新phprc设置。

  1. Navigate back to your Panel, and go to Domains > Manage Domains.
  2. Click Editnext to the domain you're working on.
  3. Don't make any changes here. Simply scroll down and click Change Settingsat the bottom of the first section.
  4. Within about 10 minutes, DreamHost will pull in your changes.
  5. If you don't see updates after 10 minutes (be patient!), contact support for help.
  1. 导航回您的面板,然后转到域 > 管理域。
  2. 单击Edit您正在处理的域旁边的 。
  3. 不要在此处进行任何更改。只需向下滚动并单击更改设置第一部分的底部。
  4. 在大约 10 分钟内,DreamHost 将拉入您的更改。
  5. 如果 10 分钟后仍未看到更新(请耐心等待!),请联系支持人员寻求帮助。
通过 SSH

If you're comfortable with the command line (and you're not using shared hosting), SSH into your server and run the following commands:

如果您对命令行感到满意(并且您没有使用共享主机),请通过 SSH 连接到您的服务器并运行以下命令:

为了 Apache阿帕奇网络服务器
sudo /etc/init.d/httpd2 restart
为了 NginxNginx网络服务器
sudo /etc/init.d/nginx stop
pkill -9 php
sudo /etc/init.d/nginx start

Your specific commands may be slightly different, but if you're comfortable with CLI then you probably know your specific command.

您的特定命令可能略有不同,但如果您熟悉 CLI,那么您可能知道您的特定命令。

回答by Sam

For people with WAMP

对于有 WAMP 的人

Left click the tray icon -> PHP -> PHP extension -> php_fileinfo

左键单击托盘图标 -> PHP -> PHP 扩展 -> php_fileinfo

It will restart your server and you're done.

它将重新启动您的服务器,您就完成了。

If that does not work, try editing the php.ini inside: C:\wamp\bin\php\php5.4.12(last part depends on your version of php)

如果这不起作用,请尝试编辑里面的 php.ini :( C:\wamp\bin\php\php5.4.12最后一部分取决于您的 php 版本)

Look for the line: ;extension=php_fileinfo.dlland remove the ;

查找该行:;extension=php_fileinfo.dll并删除;

Save and restart WAMP services.

保存并重启 WAMP 服务。