Download composer packages before install - php

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

Related

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.

Install package with composer

I want to install a package with the composer. I input the next command:
composer global require package-name
installed a package with package-name from packagist.org, but I want to install a local package with the same name.
Please, prompt me, how I can explain the composer, that it must install a local package?

How can I list up orphan packages in composer

I have a project with several outdated dependencies.
One of the dependencies is just listed up in composer.lock
I removed every package from composer.json with
composer remove <package>
but the package is still listed in composer.lock. So it seems that this is an orphan package.
If use
composer depends <package>
it returns "could not find package"
Is it safe to remove the package?
Is there a command to check for orphan packages?
Finally I just removed the package.
I checked if the package was used in the source with grep
grep -rnwi vendor/ -e "namespace"
As the the package was listed in the dev section, I run
composer install --no-dev
Then I removed the packages from the composer.lock
and run
composer install
The package was not installed again

Composer error while installing magento

I am trying to install Magento multistore and I have installed composer but still, I am getting this error..
Vendor autoload is not found.
Please run 'composer install' under application root directory.
It sounds like you have installed the composer.exe but not actually run the command composer install in your terminal.
This will install all your dependencies.
You should probably read the documentation here.

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!

Categories