Is it possible to set the installation order?
Currently I'm using Doctrine module that requires ext-mongo to be installed, but as I'm using the newer php version (7.0) I have mongodb installed instead. There's a alcaeus/mongo-php-adapter package that resolves installation problems. But there's one problem - Composer is trying to install Doctrine modules first, so that installation fails.
Currently I have to resolve this problem manually, but I can't do it any more as I'm going to pack my environment to a Docker image to let it be automatically deployed later.
From the docs of alcaeus/mongo-php-adapter
"
$ composer require alcaeus/mongo-php-adapter
If your project already has a dependency on ext-mongo, the command above may not work. This is due to a bug in composer, see https://github.com/composer/composer/issues/5030
To fix this, you can use the --ignore-platform-reqs switch when running the above command, or when running composer update with no composer.lock file present."
Related
I want to generate a Symfony application which can be compatible with PHP version up to 7.4.22.
On my local machine, PHP version is 8.0.2 but on the hosting is 7.4.22.
Symfony application is generated from local machine using standard composer command
composer create-project symfony/website-skeleton my_project_name
I look over create-project arguments to see if I could add some constrains but none seems to be useful.(or didn't figure out)
If try to upload to host the project I get this when trying to install it:
Your Composer dependencies require a PHP version ">= 8.0.0". You are running 7.4.22.
Need just a default empty project to check something on hosting.
I do not want to alter local PHP and doing the same thing on hosting could be troublesome.
You cannot add a "dependency constraint" to create-project.
E.g. Something like an imaginary create-project symfony/skeleton --dep php: "^7".
What you could do is:
first create-project
Add the config.platform key to your composer.json adjusted to your server's version (Docs.)
Run composer update
Either some packages will be downgraded if needed, or you'll get a message telling you that the new, target version is incompatible.
E.g. after doing a create-project symfony/skeleton and changing config.platform.php to 7.2, on executing composer update I get:
Your requirements could not be resolved to an installable set of packages.
Running composer create-project symfony/website-skeleton my_project_name in an example project using PHP 8 installs psr/cache in v2 and psr/link in v1.1.1. These package versions require PHP 8, and they will not work using any older version of PHP.
To avoid this, just don't run composer create-project with any later version than the one you want to use on your production system (as usually, running it with a lower PHP version than on production yields a set of packages that is compatible with the production system, while the chance is lower the other way around).
Otherwise, check whether there are such package versions using composer why-not php 7.4 before deploying and downgrade them
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.
Run this command:
composer install --ignore-platform-reqs
or
composer update --ignore-platform-reqs
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)
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
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.
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
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
I faced this problem with my cakephp project in garuda linux (arch based)
Fix :
Install php-intl using sudo pacman -S php-intl
Enable php intl by editing php config ( in my case /etc/php/php.ini ) .
add extension=intl or uncomment the existing one
restart apache or whatever you are using
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.
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
Well, after running command composer outdated I can see there's newer version of phpdocumentor/type-resolver available. Installed version is 0.2.1 and the latest one is 0.3.0. Need to say that it was indirectly installed by component I use and not by me.
Problem is when I run composer update or composer update phpdocumentor/type-resolver it says "Nothing to install or update". Why and how to fix?
probably some dependency have fixed the package release you want to install. Try so the the output of the command to check who are using and at which version the package you listed:
composer why-not phpdocumentor/type-resolver 0.3.0
NB: in the current version of the documentation of composer the command is named prohibits, so in case this doesn't work try with:
composer prohibits phpdocumentor/type-resolver 0.3.0
Hope this help
You might have version constraints blocking the upgrade in your composer.json file. This is intended to prevent adding in breaking changes. In your example, the versions are pre-release (0.*), so versioning constraints even act on the miner version.
If you are confident there are no breaking changes or you are prepared to deal with them, edit your composer.json file. Change something like:
"phpdocumentor/type-resolver": "0.2.1",
to
"phpdocumentor/type-resolver": "^0.3",
Try composer upgrade again and test it out to make sure everything is ok.
I have already use WAMP 2.5 with PHP 5.5.12, and with Composer.
The php is on:
C:\wamp\bin\php\php5.5.12
For new project, I need to use nginx and installed PHP 7.
The php is on:
C:\nginx\php
Now, using GitBash MINGW32, I tried to install laravel 5.3 using Composer create-project but it said
[InvalidArgumentException]
Could not find package laravel/laravel with version 5.3 in a version
installable using your PHP version 5.5.12.
I already put both C:\wamp\bin\php\php5.5.12 and C:\nginx\php on Windows System PATH variable.
How do I change the PHP version used by Composer?
Three ways to do this, really.
Create an alias in .bashrc to always run composer with the corresponding version
Something like alias ncomposer=`/path/to/php /path/to/composer.phar `
Specify the path to PHP version inside composer.phar itself
This is specified at the start of the file: #!/path/to/php php. Then composer should run with composer.phar
NB! The line will disappear upon self-update, so it's not a reliable solution.
Move up the path with the newest PHP version
If you place C:\nginx\php first, it should be used by default when using composer.
Hope this helps!
Although this question was solved, the answer didn't help me. I will explain how I managed to make composer to work in a version of PHP different from the one which is installed by default on my OS (PHP 7.1.1) as well as in my environment variables (these will not be changed !). Note that I'm using Xampp, but the principle remains the same for Wamp.
Starting from this answer :
Start up Git Bash
Type cd ~/ to go to your home folder
Type touch .bash_profile to create your new file.
Edit .bash_profile with your favorite editor
In my case I have a folder named php733 inside xampp folder which corresponds to PHP 7.3.3. This is this other answer that helped me in creating the alias :
alias composer733='/c/[xampp folder]/php733/php.exe /c/ProgramData/ComposerSetup/bin/composer.phar '
Then, type . .bash_profile to reload .bash_profile and update any functions you add. Notice the space between the two dots !
Finally, type this command in Git Bash :
composer733 [whatever you wan]
Example : in the project that requires at least PHP 7.1.3
Using composer :
$ composer update
This package requires php ^7.1.3 but your HHVM version does not satisfy that requirement.
Using composer733 (the alias I created) :
$ composer733 update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 98 installs, 0 updates, 0 removals
- Installing [...] (v1.11.0): Loading from cache
It works, without having to change the environment variables
I expected that
composer update videlalvaro/php-amqplib
would only update one dependency, but instead of that it updates all.
What am I missing?
PS: this dependency is defined as "videlalvaro/php-amqplib": "2.2.0" in composer.json
PPS: the composer version used is 3da05c68f9561fa822c522b1815435ff990493ff 2013-10-02 14:25:06
PPPS: the actual output:
$ composer.phar update videlalvaro/php-amqplib --no-dev
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- symfony/icu v1.2.0 requires lib-icu >=4.4 -> the requested linked library icu has the wrong version installed or is missing from your system, make sure to have the extension providing it.
- symfony/icu v1.2.0 requires lib-icu >=4.4 -> the requested linked library icu has the wrong version installed or is missing from your system, make sure to have the extension providing it.
- Installation request for symfony/icu == 1.2.0.0 -> satisfiable by symfony/icu[v1.2.0].
The command composer update videlalvaro/php-amqplib does just update that dependency. However it doesn't disable the other dependency checking that Composer does.
What the error message is complaining about is that the lib-icu is not available on your system. Apparently this would be solved by installing the PHP Intl extension.
You would see similar issues if you did a composer update on a project that required PHP 5.5 in one of it's requires, downgraded to PHP 5.4 and then ran composer update on a separate require, that didn't require PHP 5.5. Even though you wouldn't be updating the require that needs PHP 5.5, the requirements for that package would not be resolvable, and so Composer would fail.
In your case, even though you're just trying to update videlalvaro/php-amqplib to the latest version, the requirements for symfony/icu aren't met, and so the composer update fails.
Edit
To try to be helpful, I'm guessing you re-installed PHP since you last did an update, and either removed or forgot to install the PHP Intl extension. Composer can't satisfactorily satisfy the requirements your composer.json is setting, and so is defaulting to doing nothing, rather than knowingly doing an update where the requirements aren't met.
So basically, you need to install the PHP extensions that are required for your existing installed software to run, and then Composer will be able to update the single package you want to update, as well as meet the requirements for the other packages.
tl;dr:
You can list more than one dependency to update in one command:
composer update one/dependency second/dependency other/dependency
Story:
If you want to update only one dependency (composer update some/dependency), you may face an issue that request is not satisfiable due to some other dependency is installed in wrong version. And that one does not necessarily must be listed in your composer.json, it could be just dependency of some other dependency.
E.g. I wanted to update only and only google/apiclient, but calling composer update google/apiclient complained, that google/auth (dependency of apiclient) requires guzzlehttp/psr7 in version 1.2.3. I had 1.3.0 installed. The guzzlehttp/psr7 was not listed in my composer.json. What I had to do, was to call:
composer update guzzlehttp/psr7 google/apiclient
and that's it! Just update the package you want, and if composer tells you, that you need to update (or downgrade :-)) some other package, list it in the command.
I had a similar case due to security reasons on a GitHub repository.
I solved updating the dependency to a specific version like this:
composer require phpseclib/phpseclib:2.0.31
If you are working with virtual environments like docker containers (ddev, lando, etc..) before running it you should connect to the container with a:
ddev ssh
To overcome this kind of dependency problem during the update of a specific package you should specify all the specific packages versions before running their update altogether.
In your case something like this:
composer require videlalvaro/php-amqplib:2.2.0 --no-update
composer require symfony/icu:1.2.0 --no-update
composer require lib-icu:4.4 --no-update
composer update videlalvaro/php-amqplib symfony/icu lib-icu