Google cloud spatie/image deploy error, build do not complete - php

I am trying to deploy a php project via cloud run, but I keep getting the same error
Problem 1
- spatie/image is locked to version 1.10.1 and an update of this package was not requested.
- spatie/image 1.10.1 requires ext-exif * -> it is missing from your system. Install or enable PHP's exif extension.
Problem 2
- spatie/pdf-to-image is locked to version 2.1.0 and an update of this package was not requested.
- spatie/pdf-to-image 2.1.0 requires ext-imagick * -> it is missing from your system. Install or enable PHP's imagick extension.
Problem 3
- spatie/image 1.10.1 requires ext-exif * -> it is missing from your system. Install or enable PHP's exif extension.
- spatie/laravel-medialibrary 7.19.5 requires spatie/image ^1.4.0 -> satisfiable by spatie/image[1.10.1].
- spatie/laravel-medialibrary is locked to version 7.19.5 and an update of this package was not requested.
I can't find not about this package, but it's an Laravel's deppendece, so I can't uninstall, I am using docker to make this deploy
FROM composer as build
WORKDIR /app
COPY . /app
RUN composer install --no-ansi --no-interaction --no-progress --no-scripts --optimize-autoloader
FROM node:12 as node
COPY package.json ./
COPY yarn.lock ./
RUN yarn install
RUN npm install
FROM php:7.3-apache-stretch
RUN docker-php-ext-install pdo pdo_mysql
EXPOSE 8080
COPY --from=build /app /var/www/html
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf
RUN echo "Listen 8080" >> /etc/apache2/ports.conf && \
chown -R www-data:www-data /var/www/html && \
a2enmod rewrite
CMD service apache2 restart && bash
already tried:
remove as required package (Continuous deployment has been set up, but your repository has failed to build and deploy.)
php composer.phar require spatie/image-optimizer --ignore-platform-reqs
composer require google/cloud-logging google/cloud-error-reporting
update the package
update the yarn and the npm

You have to install required php extensions, in dockerfile, at line
RUN docker-php-ext-install pdo pdo_mysql
add exif:
RUN docker-php-ext-install pdo pdo_mysql exif
Installing image magick, may be complicated, see https://github.com/docker-library/php/issues/105#issuecomment-563010422 or this script - https://github.com/mlocati/docker-php-extension-installer

The problem was resolved by running install commands on a Linux(ubuntu) platform, nothing else changed, I don't even have sure yet why the error was happening

Related

GitLab PHP docker image - the requested PHP extension gd is missing from your system

I'm writing some unit tests for our application and we're using GitLab CI with GitLab Runner v11.11.1 and using Docker executor with image php:7.1.
When running composer install (our composer version is 1.10.17) I get the following error on a few required packages:
the requested PHP extension gd is missing from your system
I've tried a couple things like on our gitlab-ci.yml:
apt-get update -yqq
apt-get install -yqq libpng-dev
But that also produced the same error.
I also tried requiring ext-gd from the composer.json file:
composer require ext-gd
But I got this error:
The requested PHP extension ext-gd ^7.1 is missing from your system. Install or enable PHP's gd extension.
The last attempt I made was:
apt-get install php-common
phpenmod gd
But this gave me this error:
Unable to locate package php-common
Does anyone know how to simply enable the PHP extension gd so I can run my unit tests?
I fixed the errors when I added this to my gitlab-ci.yml file:
...
before_script:
- apt-get update -yqq
- apt-get install libjpeg-dev libpng-dev -yqq
- docker-php-ext-install gd
...
You need PHP GD library. For Debian and Debian based systems, e.g. Ubuntu, as well as Debian based Docker containers use:
apt-get install -qy php-gd
If it's still unclear, or you have older/other system just search
apt-cache search php gd
and will find out possible package candidates.
For Docker containers it seems you need a different route, so Dockerfile:
FROM php:7.1-apache-buster
RUN apt-get update
RUN apt-get upgrade -qqy
RUN php -v
RUN apt-get install -qy libpng-dev
RUN docker-php-ext-install gd

How to handle missing dependencies with composer & docker?

I have an application that I want to install for local development on my laptop with Docker. The application requires libraries from composer.
I would like to avoid installing PHP on my laptop and all necessary extensions just to be able to run composer.
I also don't want to run composer during the build inside of my application container, because I need the vendor folder on my local computer using mount binding.
It looked like the perfect solution to me to install composer though a docker container as explained here:
docker run --rm --interactive --tty \
--volume $PWD:/app \
composer install
However, when doing so, how do you resolve any PHP dependency conflicts?
For example
docker run --rm --interactive --tty \
--volume $PWD:/app \
composer require phpoffice/phpspreadsheet
will fail with
Using version ^1.14 for phpoffice/phpspreadsheet
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- phpoffice/phpspreadsheet 1.14.1 requires ext-gd * -> the requested PHP extension gd is missing from your system.
- phpoffice/phpspreadsheet 1.14.0 requires ext-gd * -> the requested PHP extension gd is missing from your system.
- Installation request for phpoffice/phpspreadsheet ^1.14 -> satisfiable by phpoffice/phpspreadsheet[1.14.0, 1.14.1].
How can I solve this kind of problems?
When the environment where you are running install, update or require commands is different from the environment where you are going to execute the code, and if you are absolutely certain that these dependencies are going to be met when the code is actually run, you do not need to check them during installation.
Just use --ignore-platform-reqs (docs).
What I usually put in my Dockerfiles when creating images for this kind of project is something like this, the the very minimum:
composer install --ignore-platform-reqs --prefer-dist
The whole thing goes like this if the artefact is being prepared for production:
composer install --ignore-platform-reqs --prefer-dist --no-scripts \
--no-progress --no-suggest --no-interaction --no-dev --no-autoloader
A couple additional steps to dump-autoload and execute post-install scripts are going to be needed in this case.
You do not elaborate how are you planning on running the result of this installation afterwards, so I'm not sure that part will be relevant for you.
Note: this is not particularly "docker" dependant. This strategy would apply any time you are creating an installation on a different machine than were you plan on running the installation.

Docker with laravel fails because of php extension

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!
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
You can change your docker image. For example try this:
FROM richarvey/nginx-php-fpm
WORKDIR /app
RUN php ./artisan config:cache && composer install

mongodb/mongodb 1.6.0 requires ext-mongodb ^1.7 -> the requested PHP extension mongodb has the wrong version (1.3.4) installed

I am newbie to php , I am trying to run laravel project with mongodb , but i am unable to install mongodb 1.60 php driver
Your requirements could not be resolved to an installable set of packages.
Problem 1
- mongodb/mongodb 1.6.0 requires ext-mongodb ^1.7 -> the requested PHP extension mongodb has the wrong version (1.3.4) installed.
- Installation request for mongodb/mongodb 1.6.0 -> satisfiable by mongodb/mongodb[1.6.0].
I tried this command
sudo apt-get install php-mongodb
this commands installs mongodb php-mongodb_1.3.4-1build1 .
when i tried to install 1.6 , response says 1.6 version not found
sudo apt-get install php-mongodb
E: Version '1.6' for 'php-mongodb' was not found
can anyone please help here.
So the mongodb/mongodb package is a php package, when you're doing the laravel install via composer, it's throwing an error stating it needs the 1.6.0 version of that package.
The problem is it requires your server php to have the ext-mongodb ^1.7 extension.
It currently has the 1.3.4 version.
You can see how to install it here: https://docs.mongodb.com/drivers/php
The problem is a mismatch of packages being installed
You could consider removing the packages and installing them as detailed on this page
[https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/][1]
See below for ubuntu 18.04
Remove old mongodb packages
sudo apt-get purge mongodb*
Add the correct repo
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
update
sudo apt-get update
Install the new package
sudo apt-get install -y mongodb-org
sudo rm -rf /tmp/mongodb-27017.sock
sudo rm -f /var/lib/mongo/mongod.lock
sudo rm -f /var/run/mongodb/mongod.pid
touch /var/run/mongodb/mongod.pid
sudo chown -R mongodb:mongodb /var/run/mongodb/
sudo chown mongodb:mongodb /var/run/mongodb/mongod.pid
sudo systemctl start mongod
Install the correct driver for mongo (note the php-version 7.2)
sudo apt-get install php7.2-mongodb

Cache PHP extensions installed with Pecl on CircleCI

We are using CircleCI as build server for php symfony application and we require the mongodb library with composer, which is dependent on the mongodb extension, that we install with pecl. So we have the following steps in our build:
- run: sudo pecl install mongodb
- run: echo -e "extension=mongodb.so" | sudo tee /usr/local/etc/php/php.ini > /dev/null
- run: cd app && composer install --no-interaction
This works fine, but the PECL mongo db extension takes half of our build time.
Is there a way to store the installed PECL extensions into the CircleCI cache?
I have tried the following:
- save_cache:
key: pecl-v1-{{ checksum "scripts/pecl-extensions.sh" }}
paths:
- /usr/local/20160303/mongodb.so
But this doesn't work - mongodb is downloaded again by PECL. What are the directories that I should try to cache in this case?
Answering my own question. There is a way to cache PHP extensions installed with PECL. One needs to know where exactly the pecl extensions are installed (pecl config-show). It seems that on the Circle CI containers this location is:
/usr/local/lib/php/extensions/no-debug-non-zts-20160303/
The extensions can be copied from this folder to a temporary directory which can be cached and restored. Restored files can be copied back with sudo.
- run: pecl config-show
- run: mkdir pecl-cache
- restore_cache:
keys:
- pecl-v1-{{ checksum "scripts/pecl-extensions.sh" }}
- pecl-v1-
- run:
name: Copying restored pecl extensions cache into extensions directory
command: sudo cp -R pecl-cache/. /usr/local/lib/php/extensions/no-debug-non-zts-20160303/
- run:
name: Install mongodb pecl extensions if mongodb.so is not there
command: >
if [ ! -f /usr/local/lib/php/extensions/no-debug-non-zts-20160303/mongodb.so ]; then
sudo pecl install mongodb ;
fi
- run:
name: Copying pecl extensions to temp directory which will be cached
command: sudo cp -R /usr/local/lib/php/extensions/no-debug-non-zts-20160303/* pecl-cache/
- save_cache:
key: pecl-v1-{{ checksum "scripts/pecl-extensions.sh" }}
paths:
- pecl-cachedocker-php-ext-install

Categories