Reputation: 828
I have been writing laravel code for quite sometime. Currently, I tried cloning a project from github and editing locally. I installed composer in my project directory but a vendor folder was not included, I tried to run composer install
but I gives me this error
Your lock file does not contain a compatible set of packages. Please run composer update
How do I resolve this?
Note: I have tried running composer update
on previous clones and that didn't work.
Upvotes: 68
Views: 217872
Reputation: 6052
If you're getting this in a CI/CD environment such as GitHub Actions, the likely cause is that you're not specifying which version of PHP to build against, causing the CI/CD to use the latest one supported - and your packages aren't likely to be compatible with this version. In my case, GitHub Actions was defaulting to using the brand-new PHP 8.4 instead of the PHP 8.1 that my lockfile was built with. To solve this with Shivam Mathur's PHP setup action, for example, simply add the php-version
parameter:
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
Upvotes: -2
Reputation: 66
Recently I've just come across of this error when I tried to run my Laravel 7 project which required php v7.* with php v8. As I forgot my php version I just tried bunch of composer command, but just got error after error.
Anyway, to solve this just downgrade/upgrade php version as required. Just search how to do that in youtube.
you can see your project required php version in composer.json
file (just if you wonder)
Also you can try following way (But though it didn't worked for me, seems it helped quite some people)
-- Open composer.json
file and change php version to something like this: "php": "^7.3|^8.1"
-- Then run composer update
Upvotes: 0
Reputation: 6350
Disclaimer, this solution will not fix the issue for PHP 8 projects.
In most cases this happens because of PHP 8 (In my case it was GitHub CI actions automatically started using PHP 8 even though my project is php 7.4)
If you have multiple PHP installations (E.g. 7.4 and 8 on the same server), this is how you can fix it.
Specify your php version in your composer.json file
"config": {
"platform": {
"php": "7.3"
}
},
If you have the lock file already committed, run composer update after you adding above line in to the composer.json and then commit the new lock file. (Please be aware composer update will upgrade your packages to latest versions)
Upvotes: 27
Reputation: 359
In my case this problem is occuring in Ubuntu 20.04 Desktop. This is due to some missing packages.
I ran the following commands to install some packages then rerun Composer install and its working properly. The commands are:
sudo apt-get install php-mbstring
sudo apt-get install php-xml
Then rerun composer install
Upvotes: 2
Reputation: 529
I solved this problem with this command:
composer self-update --1
It probably works because at time that the project was developed, composer was on another version and when change the Major version from 1 to 2 the compatibility was broke. With this command you downgrade composer and probably going to solve this
Upvotes: 14
Reputation: 4282
I had this error with Github Actions trying to deploy a Laravel app, this is probably different than the OP's case but none of the suggestions worked for me. Adding my answer here just in case there is someone else out there with a similar problem to mine.
I had to disable -q
in Github Actions and see that it was complaining about extensions not being installed.
Make sure your require
section of composer's php extensions matches the extensions:
in your github action file for shivammathur/setup-php@v2
and it will deploy again
Upvotes: 10
Reputation: 141
I had the same error deploying another project with composer, but the problem was a missing php extension.
I understand you solve your problem but for anyone seeing the same error message, here is a general guidance :
The error message Your lock file does not contain a compatible set of packages. Please run composer update
is shown each time there is a conflict during the dependency solving step of composer install. (see the relevant part in composer source code)
It doesn't inform on the real problem though, and it could be hard to guess.
To get the exact explanation you can add --verbose
option to composer install
command (the option is available to any composer command (see the doc)) : composer install --verbose
It will give you the full message explaining what exactly is preventing composer install from completing (package version conflict, missing php extension, etc.), then you'll be able to fix the problem.
Hope this could help.
Upvotes: 2
Reputation: 519
I faced this problem with my cakephp project in garuda linux (arch based)
sudo pacman -S php-intl
/etc/php/php.ini
) .
add extension=intl
or uncomment the existing oneUpvotes: 0
Reputation: 447
You should try running composer update --lock
that will update all packages and recreate the compose.lock file.
Either you can delete the composer.lock file and run composer install
that will also recreate the .lock file.
This resolved my issue.
Upvotes: 9