How to install a specific version of package using Composer?
composer require vendor/package:version
for example:
composer require refinery29/test-util:0.10.2
Composer. How to install a specific version of package based on user php version?
TL;DR: Yes.
By default, composer uses the version of the php executable to determine, which version of the package to install. This can be overridden in the config
section of composer.json, for example:
"config": {
"vendor-dir": "vendor",
"platform": {
"php": "5.6"
}
}
When someone requires your package, this version is compared to the one specified in the requirements list of your package's composer.json:
"require": {
"php": ">=7.2.0",
}
So if, for example, version 1 of your package requires php 5.6, and version 2 requires php 7.0, someone who runs composer require your-package
with php 5.6 will have version 1 installed. If someone runs it with an older version than required by any of your versions, they'll get an error stating that composer could not find a package that satisfies all the requirements, the php version being one of them.
How to get composer to install older version of a specific dependency within required range?
Since install
is meant to read from a lockfile, this option wouldn't make sense for the command.
But for update
(and if there is no lockfile, install
behaves as update
), there is the --prefer-lowest
flag (docs).
There is also the option to downgrade a specific package without affecting your composer.json
file, by running something like:
composer update --with vendor/package:2.0.1
Mind you, any of these options will modify your lockfile, so after testing you would probably need to git restore composer.lock
to go back to the original state.
Commiting a lockfile for a project by mistake should be a biggish issue. Since applications are usually built/deployed by reading the lockfile, a lockfile in an inconsistent state could break things in unexpected places.
But warding of commiting and pushing changes by mistake seems to be excessive, IMO. Developers can make changes to any file, and if they commit those "by mistake", things can break all around.
Expecting a basic "I should look what's changed before staging and commiting" seems a very low bar to me.
How to update a single library with Composer?
To install doctrine/doctrine-fixtures-bundle
with version 2.1.*
and minimum stability @dev
use this:
composer require doctrine/doctrine-fixtures-bundle:2.1.*@dev
then to update only this single package:
composer update doctrine/doctrine-fixtures-bundle
composer require specific version
If you need a installation for PHP 5.6 you should add this to your composer.json
:
"config": {
"platform": {
"php": "5.6"
}
},
https://getcomposer.org/doc/06-config.md#platform
If you need to lock to specified version of package, you may also add constraint to your composer.json
, but configuring PHP version is usually a better idea.
"require": {
"illuminate/view": "5.1.*"
},
Can't get specific version of composer package
If you want to require a specific version, and not any other, skip the caret. Installing exactly v2.0.4 of that package works using
composer require "calcinai/xero-php":"2.0.4"
Related Topics
Converting a Number With Comma as Decimal Point to Float
How to Fake $_Server['Remote_Addr'] Variable
.Htaccess Rewrite Get Variables
PHP MySQLi Prevent SQL Injection
Posting Form Fields With Same Name Attribute
How to Return Integer and Numeric Columns from MySQL as Integers and Numerics in PHP
Is Micro-Optimization Worth the Time
Send Value of Submit Button When Form Gets Posted
Finding the Subsets of an Array in PHP
MySQLi_Query() Expects Parameter 1 to Be MySQLi, Object Given
How to Iterate Over the Results in a MySQLi Result Set
Fastest Way to Serve a File Using PHP
Convert/Cast an Stdclass Object to Another Class
PHP Output Showing Little Black Diamonds With a Question Mark