I'm running a Laravel Application and added Laravel Excel, which requires phpoffice/phpspreadsheet
.
Since both dependencies are added to my composer.json...,
"maatwebsite/excel": "^3.1",
"phpoffice/phpspreadsheet": "^1.18",
I run into the following build issue:
> [vendor 3/4] RUN composer install --no-scripts:
#14 0.883 Installing dependencies from lock file (including require-dev)
#14 0.902 Verifying lock file contents can be installed on current platform.
#14 0.934 Your lock file does not contain a compatible set of packages. Please run composer update.
#14 0.934
#14 0.934 Problem 1
#14 0.934 - Root composer.json requires PHP extension ext-gd * but it is missing from your system. Install or enable PHP's gd extension.
#14 0.934 Problem 2
#14 0.934 - phpoffice/phpspreadsheet is locked to version 1.18.0 and an update of this package was not requested.
#14 0.934 - phpoffice/phpspreadsheet 1.18.0 requires ext-gd * -> it is missing from your system. Install or enable PHP's gd extension.
#14 0.934 Problem 3
#14 0.934 - phpoffice/phpspreadsheet 1.18.0 requires ext-gd * -> it is missing from your system. Install or enable PHP's gd extension.
#14 0.934 - maatwebsite/excel 3.1.33 requires phpoffice/phpspreadsheet ^1.18 -> satisfiable by phpoffice/phpspreadsheet[1.18.0].
#14 0.934 - maatwebsite/excel is locked to version 3.1.33 and an update of this package was not requested.
#14 0.934
#14 0.934 To enable extensions, verify that they are enabled in your .ini files:
#14 0.934 - /usr/local/etc/php/php-cli.ini
#14 0.934 - /usr/local/etc/php/conf.d/docker-php-ext-bz2.ini
#14 0.934 - /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini
#14 0.934 - /usr/local/etc/php/conf.d/docker-php-ext-zip.ini
#14 0.934 You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
------
executor failed running [/bin/sh -c composer install --no-scripts]: exit code: 2
My Dockerfile:
# PHP Dependencies
FROM composer:2.1.6 as vendor
COPY . /app
RUN composer install \
--no-scripts
RUN composer dump-autoload
# Frontend
FROM node:16.7 as frontend
COPY . /app
WORKDIR /app
RUN npm install && npm run dev && rm -rf node_modules
RUN ls -R -lsah /app
# Application
FROM php:7.4.21-apache
# Install system dependencies
RUN apt-get update && apt-get install \
git \
curl \
libpng-dev \
libxml2-dev \
zip \
unzip -y
RUN docker-php-ext-install pdo_mysql gd
RUN a2enmod rewrite
COPY --chown=www-data:www-data . /var/www/html
COPY --chown=www-data:www-data --from=vendor /app/vendor/ /var/www/html/vendor/
COPY --chown=www-data:www-data --from=frontend /app/public/js/ /var/www/html/public/js/
COPY --chown=www-data:www-data --from=frontend /app/public/css/ /var/www/html/public/css/
COPY --chown=www-data:www-data --from=frontend /app/public/mix-manifest.json /var/www/html/public/mix-manifest.json
RUN php artisan optimize:clear
I'm not sure where I shall continue. When I build the container without COPY --chown=www-data:www-data --from=vendor
, I can get some php information:
ext-gd is installed:
root@303d9b2b0694:/var/www/html# php -ini | grep gd
Additional .ini files parsed => /usr/local/etc/php/conf.d/docker-php-ext-gd.ini,
gd
This also looks fine, doesn't it?
root@303d9b2b0694:/var/www/html# php --ini
Configuration File (php.ini) Path: /usr/local/etc/php
Loaded Configuration File: (none)
Scan for additional .ini files in: /usr/local/etc/php/conf.d
Additional .ini files parsed: /usr/local/etc/php/conf.d/docker-php-ext-gd.ini,
/usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini,
/usr/local/etc/php/conf.d/docker-php-ext-sodium.ini
my require composer:
"require": {
"php": "^7.4|^8.0",
"ext-gd": "*",
"ext-json": "*",
"doctrine/dbal": "^3.1.1",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.3.0",
"jenssegers/agent": "^2.6",
"laravel/framework": "^8.12",
"laravel/jetstream": "^2.3.11",
"laravel/sanctum": "^v2.11.2",
"laravel/tinker": "^v2.6.1",
"league/oauth2-client": "^2.6",
"livewire/livewire": "^v2.5.1",
"maatwebsite/excel": "^3.1",
"microsoft/microsoft-graph": "^1.34.0",
"motze92/office365-mail": "^2.0.7",
"phpoffice/phpspreadsheet": "^1.18",
"predis/predis": "^1.1"
},
last but not least, the modules:
root@303d9b2b0694:/var/www/html# php -m
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
ftp
gd
hash
iconv
json
libxml
mbstring
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
SimpleXML
sodium
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib
[Zend Modules]
My php.info
shortcut in regard to the PHP extension ext-gd
:
gd
GD Support => enabled
GD Version => bundled (2.1.0 compatible)
GIF Read Support => enabled
GIF Create Support => enabled
PNG Support => enabled
libPNG Version => 1.6.36
WBMP Support => enabled
XBM Support => enabled
BMP Support => enabled
TGA Read Support => enabled
The reason for this seams to be in the FROM composer:2.1.6 as vendor
stage. I thought the error came from the FROM php:7.4.21-apache
stage which took me lots of time in playing around with modules and libraries.
I'll now install GD on the composer
stage and see if that solves the problem
I greatly appreciate any hint or advise! Many Thanks!
I finally solved this. The reason is very simple. In the first stage, where composer is Installing dependencies from lock file where no PHP extension ext-gd
installed.
So I've added the extension to the FROM composer:2.1.6 as vendor
stage:
# PHP Dependencies
FROM composer:2.1.6 as vendor
RUN apk add --no-cache freetype libpng libjpeg-turbo freetype-dev libpng-dev libjpeg-turbo-dev && \
docker-php-ext-configure gd \
--with-freetype \
--with-jpeg \
NPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) && \
docker-php-ext-install -j$(nproc) gd && \
apk del --no-cache freetype-dev libpng-dev libjpeg-turbo-dev
COPY . /app
RUN composer install \
--no-scripts
RUN composer dump-autoload
Hopefully this may help others in the community as well.