Running Laravel
on an appache
server.
Upon building the image with docker-compose up --build
with the following Dockerfile
FROM php:7.3-apache-stretch RUN apt-get update -y && apt-get install -y libpng-dev RUN docker-php-ext-install pdo pdo_mysql gd FROM composer:1.9.0 as build WORKDIR /app COPY . /app RUN composer global require hirak/prestissimo && composer install
I am getting the error message:
phpoffice/phpspreadsheet 1.13.0 requires ext-gd * -> the requested PHP extension gd is missing from your system.
This happens when the composer install
command runs.
As you can see up, I am actually installing gd from php, so it should not give me this error message.
Do you have any idea how I can solve it?
Thanks!
Advertisement
Answer
It’s happen, because you are using multistage building and your composer
second stage have nothing to do with previous build using PHP
container. Primary use case with multistaging is to produce some useful artefacts which can be used later.
So what I suggest is to copy composer file from composer
image, then place it somewhere in your php
container.
I will give you my solution which is working perfectly for me with laravel/symfony etc.
FROM php:7.4.4-fpm # We copy composer from it's original image to our php container to use it later. COPY --from=composer:1.9 /usr/bin/composer /usr/bin/composer WORKDIR /var/www ARG USER_ID RUN useradd -s /bin/bash -d /home/user/ -m -G sudo,www-data user -u $USER_ID RUN apt update && apt install -y zip unzip wget zlib1g-dev libicu-dev RUN docker-php-ext-install pdo_mysql intl opcache gd USER user RUN wget https://get.symfony.com/cli/installer -O - | bash ENV PATH="/home/user/.symfony/bin:${PATH}" COPY php.ini /usr/local/etc/php # You can also run here composer install, depends on your use case