222

When I run a composer update I get this error message:

Loading composer repositories with package information
Updating dependencies (including require-dev)
    Failed to download psr/log from dist: The zip extension and unzip command are both missing, skipping.
The php.ini used by your command-line PHP is: /etc/php/7.0/cli/php.ini
    Now trying to download from source

What do I need to do to enable the zip and unzip commands so that composer can download dependencies?

b85411
  • 9,420
  • 15
  • 65
  • 119
  • 1
    Workaround: Use `composer update --prefer-source` I had this issue when trying to `composer update` phpspec. `Failed to download symfony/polyfill-ctype from dist: The zip extension and unzip command are both missing, skipping.` I am on a Mac and had problems making Homebrew work to install php extensions. So, my quick fix was to force `composer` _not_ to need to use zip by adding the --prefer-source option. This means it downloads the repo instead of a zipped package. Not a long term solution but handy to know. – John Walker Dec 29 '19 at 23:23

25 Answers25

436

Depending on your flavour of Linux and PHP version these may vary.

(sudo) yum install zip unzip php-zip
(sudo) apt install zip unzip php-zip

This is a very commonly asked question, you'll be able to find more useful info in the aether by searching <distro> php <version> zip extension.

Arrisar
  • 4,552
  • 1
  • 13
  • 15
  • 64
    For Ubuntu `apt-get install php-zip` is sufficient – Olaf Dietsche Nov 04 '17 at 15:45
  • 1
    @OlafDietsche How do you know/determine when to install `php[version]-package` vs `php-package` for any given package? Would love to know as I usually just go with the `php[version]-package` version, but perhaps that's not optimal… – elbowlobstercowstand Jul 15 '18 at 05:19
  • @elbowlobstercowstand `php-` is the default version. These packages just depend on the most recent version. If you need some specific (usually older) version, you install `php-`. – Olaf Dietsche Jul 15 '18 at 09:17
  • It also works for `# yum install zip unzip php7.2-zip` (on CentOS 7) – Pathros Oct 24 '18 at 23:28
  • 3
    People keep giving instructions to install php-zip as well as zip/unzip. It makes no sense that it needs both. – jgmjgm May 13 '19 at 17:49
  • people using docker (nov '19) use : RUN apt-get install -y zlib1g-dev \ && docker-php-ext-install zip – naman1994 Nov 11 '19 at 02:30
  • I found that @naman1994's proposal is missing `libzip-dev` for dockerfiles `from php:7.3`. So it should be `RUN … apt-get install -yqq … zlib1g-dev libzip-dev && docker-php-ext-install zip` – Thomas Praxl Dec 14 '19 at 12:36
  • 2
    Also, you really should install unzip. Otherwise composer will complain: `As there is no 'unzip' command installed zip files are being unpacked using the PHP zip extension. This may cause invalid reports of corrupted archives. Besides, any UNIX permissions (e.g. executable) defined in the archives will be lost. Installing 'unzip' may remediate them.` So it should be `RUN … apt-get install -yqq … zlib1g-dev libzip-dev unzip && docker-php-ext-install zip` – Thomas Praxl Dec 14 '19 at 13:23
52

For servers with PHP 5.6

sudo apt-get install zip unzip php5.6-zip
Goke Obasa
  • 4,328
  • 1
  • 18
  • 26
Olawale
  • 741
  • 7
  • 11
51

Not to belabor the point, but if you are working in a Dockerfile, you would solve this particular issue with Composer by installing the unzip utility. Below is an example using the official PHP image to install unzip and the zip PHP extension for good measure.

FROM php:7.4-apache

# Install Composer
COPY --from=composer /usr/bin/composer /usr/bin/composer

# Install unzip utility and libs needed by zip PHP extension 
RUN apt-get update && apt-get install -y \
    zlib1g-dev \
    libzip-dev \
    unzip
RUN docker-php-ext-install zip

This is a helpful GitHub issue where the above is lovingly lifted from.

DJ Sipe
  • 1,286
  • 13
  • 12
  • I enjoyed your prose in this answer. Thank you – ortonomy Mar 17 '21 at 09:24
  • In my case, doing apt-get install -y zlib1g-dev libzip-dev unzip gets the error gone. – jpruiz114 Jun 01 '21 at 23:41
  • If warning comes from composer executed in php:7.4-cli with Dockerfile, by installing just `zip` warning goes away. `RUN apt-get update && apt-get install -y zip`. It didn't request for unzip, libs nor docker-php-ext... – Vladimir Vukanac Sep 08 '21 at 21:54
44

For Windows, in case you're using a locale development environment like XAMPP, just locate the php.ini file (C:\xampp\php in my case), open it and remove the semicolon from the following line.

;extension=zip

Restart your Apache webserver and it will work fine.

eduardo a
  • 152
  • 4
  • 17
Gentlebeer ツ
  • 625
  • 6
  • 8
26

For Debian Jessie (which is the current default for the PHP image on Docker Hub):

apt-get install --yes zip unzip php-pclzip

You can omit the --yes, but it's useful when you're RUN-ing it in a Dockerfile.

Peter Breuls
  • 406
  • 4
  • 4
24

For older Ubuntu distros i.e 16.04, 14.04, 12.04 etc

sudo apt-get install zip unzip php7.0-zip
Goke Obasa
  • 4,328
  • 1
  • 18
  • 26
16

I had PHP7.2 on a Ubuntu 16.04 server and it solved my problem:

sudo apt-get install zip unzip php-zip

Update

Tried this for Ubuntu 18.04 and worked as well.

Aqib Ashef
  • 623
  • 8
  • 19
13

Please check your composer status first

composer diagnose 

If the status showing

zip: extension not found, unzip not available, 7-Zip not available

then

  1. Open your XAMPP Server
  2. Apache -> config button ->Click "PHP(php.ini)"
  3. Find "zip"
  4. ";extension = zip will shown
  5. Remove the semicolon and save the file
  6. Restart your XAMPP Apache

Now

composer create-project laravel/laravel <<project_name>>

or

laravel new <<project_name>>
vithushan
  • 131
  • 1
  • 3
10

I'm Using Ubuntu and with the following command worked

apt-get install --yes zip unzip

Oscar Gallardo
  • 2,240
  • 3
  • 27
  • 47
6

For Windows Users:

Locate your php.ini and open it with a text editor.

Search for 'zip'. If you're using PHP 8.2, you'd probably find it on line 952 written like this: ;extension=zip

Remove the ';' so it looks like this-> extension =zip Save and you're good to go!

Moses Aweda
  • 61
  • 1
  • 3
5

On docker with image php:7.2-apache I just needed zip and unzip. No need for php-zip :

apt-get install zip unzip

or Dockerfile

RUN ["apt-get", "update"]
RUN ["apt-get", "install", "-y", "zip"]
RUN ["apt-get", "install", "-y", "unzip"]
Armel Larcier
  • 15,747
  • 7
  • 68
  • 89
5

For PHP8.2 (Windows)

As stated here: https://www.php.net/manual/en/zip.installation.php#zip.installation.new.windows

As of PHP 8.2.0, php_zip.dll DLL must be enabled in php.ini. Previously, this extension was built-in.

You will need to manually enable this extension within your php.ini by adding extension=php_zip.dll

For a list of installed extensions you can run:

php -m

or if you have grep installed even easier would be:

php -m | grep "zip"
zanderwar
  • 3,440
  • 3
  • 28
  • 46
4

If you are using Ubuntu and PHP 7.2, use this...

sudo apt-get update
sudo apt-get install zip unzip php7.2-zip
aphoe
  • 2,586
  • 1
  • 27
  • 31
4

I got this error when I installed Laravel 5.5 on my digitalocean cloud server (Ubuntu 18.04 and PHP 7.2) and the following command fixed it.

sudo apt install zip unzip php7.2-zip

Joyal
  • 2,587
  • 3
  • 30
  • 45
4

As of PHP 8.2.0, php_zip.dll DLL must be enabled in php.ini. Previously, this extension was built-in.

you can do that:

edit php.ini file and remove semicolon in the line

;extension=zip 

save the file and you good to go..

A. Rokbi
  • 503
  • 2
  • 8
3

Actually composer nowadays seems to work without the zip command line command, so installing php-zip should be enough --- BUT it would display a warning:

As there is no 'unzip' command installed zip files are being unpacked using the PHP zip extension. This may cause invalid reports of corrupted archives. Installing 'unzip' may remediate them.

See also Is there a problem with using php-zip (composer warns about it)

Alex
  • 32,506
  • 16
  • 106
  • 171
3

PHP-ZIP needs some dependancies or library missing, depends on the image from Dockerfile you need to install them first

RUN set -eux \
   && apt-get update \
   && apt-get install -y libzip-dev zlib1g-dev \
   && docker-php-ext-install zip
Pascal Tovohery
  • 888
  • 7
  • 19
3

PHP 8.1

apt-get install --yes zip
Cyril
  • 3,048
  • 4
  • 26
  • 29
fabpico
  • 2,628
  • 4
  • 26
  • 43
3

After run

apt install php-zip

and run again

composer require ...

I get the next warning and suggestion

As there is no 'unzip' nor '7z' command installed zip files are being unpacked using the PHP zip extension.

This may cause invalid reports of corrupted archives. Besides, any UNIX permissions (e.g. executable) defined in the archives will be lost.

Installing 'unzip' or '7z' (21.01+) may remediate them.

As there is no 'unzip' nor '7z' command installed zip files are being unpacked using the PHP zip extension.

This may cause invalid reports of corrupted archives. Besides, any UNIX permissions (e.g. executable) defined in the archives will be lost.

Installing 'unzip' or '7z' (21.01+) may remediate them.

So I suggest install unzip first.

apt install unzip
Salvador Rueda
  • 855
  • 2
  • 7
  • 15
2

The shortest command to fix it on Debian and Ubuntu (dependencies will be installed automatically):

sudo apt install php-zip
DevonDahon
  • 7,460
  • 6
  • 69
  • 114
2

Try this for PHP 7.4:

sudo apt-get install zip unzip php7.4-zip

And for PHP 8.0:

sudo apt-get install zip unzip php8.0-zip
Pejman Kheyri
  • 4,044
  • 9
  • 32
  • 39
2

if you are using XAMPP to run your php code in the latest release, zip extensions are commented out you have to activate them yourself. Navigate to C:\xampp\php, open the php.ini file and find the commented line and uncomment as follows by removing starting semicolon

;extension=zip

to

extension=zip

save and rerun you command. works like magic!

It's VIN
  • 152
  • 7
0
apt-get install zip

I'm running a docker container and this helped me

docker-compose exec app apt-get install zip
cottontail
  • 10,268
  • 18
  • 50
  • 51
youcef
  • 29
  • 4
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 16 '22 at 08:20
0

locate php.ini and search 'zip', then uncomment/remove semicolon

Dalan Dan
  • 11
  • 1
0

I fixed this error in my Windows system by uncommenting zip ext in php.ini.

cottontail
  • 10,268
  • 18
  • 50
  • 51