Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing PHP-zip on a php:7.4-fpm image

Tags:

php

docker

libzip

I want to install php-zip on my docker image (the end goal is to use the PhpWord Library). I use the php:7.4-fpm, which runs on Debian.

In my dockerfile, i use the command :

RUN apt-get update docker-php-ext-install zip

When executed, the script crashes because it can't find /usr/src/php/ext/libzip.

So i add a good old "apt-get install libzip", but it can't locate the package. Same thing if it try to install "libzip4" :

checking for libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0... no
configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:

No package 'libzip' found
No package 'libzip' found
No package 'libzip' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix.

Alternatively, you may set the environment variables LIBZIP_CFLAGS and LIBZIP_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
ERROR: Service 'webapi' failed to build : The command '/bin/sh -c apt-get update          &&       apt-get install libzip4          && docker-php-ext-install zip' returned a non-zero code: 1

I assume either libzip4 isn't a valid version or it can't make the link between libzip and libzip4.

The main issue is that, without that library, i'm stuck and can't install the extension at all. Also i'm quiet a rookie when it comes to docker so i call out your help !

Thanks for your time !

like image 575
Mouke Avatar asked Oct 23 '20 12:10

Mouke


People also ask

How can I tell if PHP zip is enabled?

You will know that the ZipArchive class is not enabled if you cannot see: “Zip” configuration “enabled”. You can also check whether the Zip module is enabled using the CLI. Show compiled in modules using: php -m. Or you can use “php -m” to show the PHP information in the CLI.

What is PHP zip module?

PHP zip archive is a process or tool installed on your web hosting server that enable PHP script / command to archive a file or zip and unzip a file or you can say compress a file and extract a compressed file.

What is Docker PHP ext install?

docker-php-ext-install This command is used to install and start PHP extensions. Note: The "source package" needs to be placed under / usr/src/php/ext. By default, the PHP container does not have the directory / usr/src/php, which needs to be generated using docker PHP source extract.

How do I compile PHP with ZIP support?

As of PHP 7.4.0, in order to use these functions you must compile PHP with zip support by using the --with-zip configure option. Previously, zip support had to be enabled by using the --enable-zip configure option. As of PHP 7.4.0, the bundled libzip is removed.

How to install Apache2 or nginx with PHP / PHP-FPM?

Save the file and exit. At this point, Apache2 or Nginx with PHP or PHP-FPM should be installed and ready to use. you can test PHP / PHP-FPM settings by creating a blank file. Then add the line in the file and save. Save the file and open your browser and browse to the server name or IP address followed by /phpinfo.php

How to install PHP on Ubuntu 20 04?

Click on the Terminal application icon to open it. Alternatively, you can hit the CTRL, ALT, and T keys on your keyboard at the same time to open the Terminal application automatically. Note: Ubuntu 20.04 ships with PHP 7.4 in its upstream repositories. This means that if you attempt to install PHP without a specified version, it will use 7.4.

What version of libzip is required for PHP 7?

As of PHP 7.4.0, the bundled libzip is removed. As of PHP 7.3.0, building against the bundled libzip is discouraged, but still possible by adding --without-libzip to the configuration. A --with-libzip=DIR configure option has been added to use a system libzip installation. libzip version 0.11 is required, with 0.11.2 or later recommended.


1 Answers

Ok, so the issue is that you have to guess that the package you need to install is called "libzip-dev", not just "libzip".

So the solution was :

RUN apt-get update \
     && apt-get install -y libzip-dev \
     && docker-php-ext-install zip
like image 170
Mouke Avatar answered Oct 05 '22 07:10

Mouke