How to handle missing dependencies with composer & docker? - php

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.

Related

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

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

I cannot install Laravel with Composer (ext-zip extension is missing)

I tried to install Laravel with Composer on my Debian 9 terminal with
composer global require laravel/installer
But I get the following errors:
Using version ^3.0 for laravel/installer
./composer.json has been created
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
- laravel/installer v3.0.1 requires ext-zip * -> the requested PHP extension zip is missing from your system.
- laravel/installer v3.0.0 requires ext-zip * -> the requested PHP extension zip is missing from your system.
- Installation request for laravel/installer ^3.0 -> satisfiable by laravel/installer[v3.0.0, v3.0.1].
To enable extensions, verify that they are enabled in your .ini files:
- /opt/lampp/etc/php.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
Installation failed, deleting ./composer.json.
I tried to install the PHP ext Zip extension with:
apt-get install php7.4-zip
and
apt-get install php-zip
and also edit the php.ini file uncommenting the following lines:
extension=php_zip.dll
extension="zip.so"
But nothing works and I have the same errors...
Make sure to restart the webserver after the change
php -m to list the compiled modules
it happened to me once (on plesk) that composer was using a different php version than to use php itself
You could try php composer.phar(the location of that) and check the results
If Installing laravel is what matters here
here are some possible solutions
composer create-project laravel/laravel [dir]
or git clone https://github.com/laravel/laravel.git then cd to that directory, usually laravel, so cd laravel then composer install
I had the same problem as you.
I could see that I was lacking the zip extension by doing
php -m
I did
apt search php | grep zip
to see if there was a package I could install, I found php-zip, so I did
sudo apt install php-zip
after which php -m showed zip in the list.
Then I tried the command to install Laravel again
composer global require laravel/installer
and it succeeded.

Download composer packages before install

I want to force to composer to download all packages before to install it and to speedup the dependencies installation on projects.
On production environment, I don't want to wait to packages download, it must be installed from cache.
Something like:
$> composer download-install # Currently not exists
$> composer install # Install from previously cached packages.
There are any composer option to do it?
Thanks!
There's a composer package that does exactly that!
Require it globally like this:
$ composer global require hirak/prestissimo
Then just a regular composer install will prefetch all the packages first and then install them as if they're from cache.
$ composer install
Read more at https://github.com/hirak/prestissimo

How can I solve "laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system"?

When I run composer install on command promp, there exist error like this :
Problem 1
- Installation request for laravel/horizon v1.1.0 -> satisfiable by laravel/horizon[v1.1.0].
- laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system.
To enable extensions, verify that they are enabled in your .ini files:
- C:\xampp-7.1\php\php.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
How can I solve this error?
Run composer with the --ignore-platform-reqs option and specify pcntl and posix
composer install --ignore-platform-reqs
As per the accepted answer, but you can add this to your composer.json so that you don't have to run --ignore-platform-reqs all the time
"config": {
"platform": {
"ext-pcntl": "8.0",
"ext-posix": "8.0"
}
}
install horizon this way :
composer require laravel/horizon --ignore-platform-reqs
then run
php artisan horizon:install
If you are using docker based on a Unix image you can add it with the docker utility:
docker-php-ext-install pcntl
You can then confirm that this extension is installed and enabled inside of your container:
?> php -i | grep pcntl
/usr/local/etc/php/conf.d/docker-php-ext-pcntl.ini,
pcntl
pcntl support => enabled
pcntl extension is not supported on Windows. (based on your XAMPP information)
Please see these github issues on laravel/horizon page #131, #78.
I suggest you use Laravel Homestead on your Windows system, It is easy to setup and will save you from many of the similar problems in future.
Just run the following:
composer install --ignore-platform-reqs
Note: pcntl is not supported on Windows
add this line
RUN docker-php-ext-install pcntl
before
RUN composer install
This works for me
composer require laravel/horizon --ignore-platform-reqs
Hopefully it will help.
The answer to simply ignore the dependency is wrong. That isn't going to give you a working version of Horizon or whatever package you may be hoping to install. The dependencies must be installed.
Examples of how to install:
APK
sudo add php8-pcntl php8-pcntl
Yum
sudo yum install -y php-pcntl php-posix
I have installed PHP 7.2 instead of 7.1 and everything works fine now. It appears that pcntl was not present in 7.1 but it's installed with php 7.2.
I have some problem and composer install --ignore-platform-reqs works for me
Thanks
You need to install the package while ignoring the platform requirements.
composer require laravel/horizon --ignore-platform-reqs
Then run
php artisan horizon:install
If you're running on windows 10 without homestead you can enable the linux subsystem and run horizon through that.
https://www.windowscentral.com/how-install-bash-shell-command-line-windows-10
Then install the requirements
sudo apt install php7.2-fpm php7.2-mbstring php7.2-xmlrpc php7.2-soap php7.2-gd php7.2-xml php7.2-cli php7.2-zip php7.2-mysql
This also can run laravel envoy too which doesn't work on windows.
It's a nice lightweight solution
$composer install --ignore-platform-reqs ext-pcntl
If you use Windows and get that issue - you should just ignore it since Horizon works fine without the extension and doesn't require it on Windows.
So basically you must use the next
composer require laravel/horizon --ignore-platform-reqs
Good luck!

Can't Create a new laravel app

Am trying to create a new laravel project, in the past i have successfully created a new laravel project by running laravel new blog, i just tried it about 2hrs ago and i get this error.
nkossy Desktop $ laravel new blog
Crafting application...
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for symfony/thanks v1.0.1 -> satisfiable by symfony/thanks[v1.0.1].
- symfony/thanks v1.0.1 requires composer-plugin-api ^1.1 -> no matching package found.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
Application ready! Build something amazing.
am running Ubuntu 16.04 with php7.1 installation
Running composer update doesn't help
Remove "symphony/thanks" dependency in your project's composer.json plugin and run 'composer update' after.
Here is what I did.
First, uninstall composer, Follow instructions here
then reinstall composer by running the following command.
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
Lastly run laravel new app, done.

Categories