Composer require ext-zip fails

35,036

Solution 1

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

Solution 2

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.

Solution 3

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

Share:
35,036

Related videos on Youtube

Jeffrey L. Roberts
Author by

Jeffrey L. Roberts

Updated on November 10, 2020

Comments

  • Jeffrey L. Roberts
    Jeffrey L. Roberts over 3 years

    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.
    
    • Nico Haase
      Nico Haase about 5 years
      What makes you think that you should install it using composer? That's a PHP extension which you have to install either through your OS's package system or by downloading it manually
    • Jeffrey L. Roberts
      Jeffrey L. Roberts about 5 years
      I have updated the question with a screenshot from my IDE
    • Nico Haase
      Nico Haase about 5 years
      And still, that extension is not to be installed using composer
    • Jeffrey L. Roberts
      Jeffrey L. Roberts about 5 years
      I have updated the question with a screenshot with more details... If its not supposed to be installed with composer, maybe composer is supposed to let users of the application know that extension is required ?
    • Karol Gasienica
      Karol Gasienica about 5 years
      Well it's not missing I guess, it's just your IDE says it is not in composer.json but it is a part of PHP extension. Do you have any error when executing code? If yes please share it with us.
  • Nico Haase
    Nico Haase about 5 years
    Can you explain further how that solves the given message? The IDE obviously gives some connection to composer.json
  • Nico Haase
    Nico Haase about 5 years
    And can you add some explanation that covers why the message popped up initially, and what your code does against it?
  • Grayside
    Grayside about 5 years
    Answered by stackoverflow.com/a/56220471/38408, the ext- dependencies in composer are system requirements that composer can validate but not manage. Instead, other server configuration mechanisms are used to set up the server with those packages.
  • OZZIE
    OZZIE over 4 years
    sure but what if I just get annoyed by seeing all the code marked like some kind of error in the IDEA, I don't want to see it or modify composer.json just because of it :)