Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install zip module on php 8.2 amazon linux elastic beanstalk

I'm pretty sure the zip extension was included by default in the amazon managed php elb image.

The usual way to do this was adding a config file like this to .ebextensions

packages:
    yum:
        php-zip70: []

However that doesn't work anymore.

Any ideas?

like image 460
asdfasdfsdfga Avatar asked Jul 07 '26 16:07

asdfasdfsdfga


2 Answers

@asdfasdfsdfga gave some good hints. A more modern approach:

Add the file .platform/hooks/prebuild/install-php-zip.sh

#!/usr/bin/env bash

yum -y install libzip libzip-devel

# Will enable zip extension in /etc/php.ini
pecl upgrade zip 

Note that "pecl install zip" will return an error code if already installed (?!), resulting in your deployment failing the second time you attempt to deploy. Instead, use upgrade, which will install if not already installed, and complete successfully if already installed.

The pecl command will insert 'extension="zip.so"' at the top of /etc/php.ini.

like image 176
Mark Bench Avatar answered Jul 10 '26 06:07

Mark Bench


This is the solution I ended up with.

if test returns true then run command

files:
  "/etc/php.d/20-zip.ini":
    mode: "000644"
    owner: root
    group: root
    content: |
      extension=zip.so
commands:
  01_install_libzip:
    command: "dnf -y install libzip libzip-devel"
  02_install_zip:
    test: "php -r \"exit(extension_loaded('zip') ? 1 : 0);\""
    command: "pecl install zip"
like image 37
Andrew Sohn Avatar answered Jul 10 '26 04:07

Andrew Sohn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!