Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composer require ext-zip fails

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.
like image 805
Jeffrey L. Roberts Avatar asked May 20 '19 11:05

Jeffrey L. Roberts


3 Answers

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

like image 113
Yevhen Kuzmenko Avatar answered Nov 19 '22 19:11

Yevhen Kuzmenko


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.

like image 10
Alister Bulman Avatar answered Nov 19 '22 18:11

Alister Bulman


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

like image 9
Nico Haase Avatar answered Nov 19 '22 18:11

Nico Haase