Composer require ext-zip fails

2020-04-03 03:11发布

I am told by PHPStorm that I need to composer require ext-zip, however, that command is failing...

PHPStorm says

enter image description here

The command I am issuing is

composer require ext-zip

results in

Your requirements could not be resolved to an installable set of packages.

and

Installation failed, reverting ./composer.json to its original content.

3条回答
等我变得足够好
2楼-- · 2020-04-03 04:00

Solution #1 - add ext-zip to your required section of composer.json:

{
    "require" : {
        "ext-zip": "*"
    }
}

Solution #2 - install php-zip extension:

Windows:

Uncomment this line in your php.ini

;extension=php_zip.dll

Linux:

sudo apt-get install php-zip

or

sudo apt-get install php7.0-zip (make sure you typed YOUR php version, you can check your version by doing php -v command)

Then, you need to restart your web server.

sudo service apache2 restart

查看更多
手持菜刀,她持情操
3楼-- · 2020-04-03 04:10

The given hint comes from PhpStorm, not from composer itself: your IDE has detected that your code uses a method (or in this case: the ZipArchive class) that is only available when the ZIP extension is enabled. But your composer.json did not contain that requirement so far.

So, PhpStorm asks you to add this requirement to the JSON file to make the requirements to run your code more precise. How you solve that requirement is up to you: the best way would be to install that extension, but that is out of composer's scope

查看更多
够拽才男人
4楼-- · 2020-04-03 04:11

If your code runs OK - you've already got the zip extension installed on your machine. PHPStorm adds this suggestion to ensure that anywhere else that the project is deployed also has the right extensions too.

Manually adding the line in your composer.json file (require block) "ext-zip": "*", (and others that it can suggest, such as ext-apc, ext-redis and ext-json, as well as any others that you might be using) will make sure that when you deploy it composer can also check that the appropriate extra items are installed.

It's only a warning though, and you could ignore it - or you can allow composer to make sure that your servers are setup as they would be needed to run your code, and do things with zip-files. If your server doesn't have ext-zip installed, composer install would complain, and stop - saving issues later when you discover that code fails without the zip extension, et al.

查看更多
登录 后发表回答