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
Related
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.
I tried install package watson/rememberable on localhost and it's installed successfully but when tried install it on shared hosting package killed and added package name to composer.json file, but not installed source code to vendor folder. I tried install package by clearing composer & Laravel caches but package not installed. How I can install it correctly?
To install the most recent version, run the following command:
composer require watson/rememberable
OR
Add to composer.json file:
"require": {
"watson/rememberable": "^3.1",
},
After, Run this command in the command prompt: composer update
Maybe you are in production mode. In the .env file change:
APP_ENV=local
Then try installing again.
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?
When I use the command:
git add composer.lock
inside the folder of my project I get the message:
fatal: pathspec 'composer.lock' did not match any files
How can I fix this problem?
All I needed to do was install the xml from my php version.
In my case, my version is 7.1, so I did:
sudo apt-get install php7.1-xml
So I used the commands:
composer install
composer update
And finally I was able to add the composer.lock command:
git add composer.lock
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