How to change php version in composer dependencies
You don't change package dependencies, that's the responsibility of the package maintainer. Either see if there is another version available that requires the same or lower version of PHP than you have installed in your environment or install the required PHP version.
It appears that MAMP Pro has support for PHP 8.1 although this question seems to have a solution without requiring the Pro version.
How to Actually change PHP Version that used by composer?
I don't really know how do you run the composer script so my answer can be useless for you.
You have two different versions of php, so you have two binary files for each version, so you can use needed binary file to run the composer from your command line:
$ /path/to/needed/binary/php composer.phar install
But it can be a really bad idea. Libraries in the composer can depend of others and those can depend from php version. Your composer loads libraries which are relying on php version wich is currently running. So it can load libraries which will not work in other php version.
Change PHP version used by Composer on Windows
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!
Laravel Composer sees wrong PHP Version
I've had this problem too. If you don't want to update all your composer packages, you can solve this issue by manually changing the composer.lock
file and writing your actual PHP version in platform > php
in the JSON object.
Example
...
"platform": {
"php": "7.1"
}
...
Although it works, the most recommended way to do this would be deleting your composer.lock
file, changing the platform > php
version in composer.json
and then executing composer install
.
How to switch php version when running composer?
IF you have multiple php version installed in your system
you can run composer with different versions like
In linux
PHP
usr/local/php usr/bin/composer install
for PHP 7.1
usr/local/php7.1 /usr/local/composer install
actually the idea is which version you wants to run get its bin path and then run the composer.
In Windows.
path/to/php.exe composer install
Hope this helps
How to downgrade or install a specific version of Composer?
Assuming a regular composer installation, to rollback to version 1 of composer, you simply execute:
composer self-update --1
When you want to go back to version 2 (which you should, after updating or removing the incompatible plugins):
composer self-update --2
The above will take you to the latest on any of the two major versions.
You can also "update" to a specific version just by passing the version number to self-update
:
composer self-update 1.10.12
composer self-update 2.0.7
After performing any self-update
, you can specify --rollback
to go back to the previously installed version.
composer self-update
composer self-update --rollback
Finally, if you are feeling adventurous, you can update to a pre-release version by executing:
composer self-update --preview
PHP: Composer uses PHP version older than the used version (on shared hosting)
Note that .htaccess
only affects the Apache configuration. When accessing the server via SSH the file is completely ignored/useless.
Some providers install multiple versions of PHP, making it available by typing php7.3
, and the php
is a simple alias to the current default version. Probably the composer is set up in a way to use a different version of the default (not sure how/why) while your ssh session is using another.
Since your php -v
is reporting the desired version. I would suggest downloading composer.phar
and running it locally via php composer.phar ...
instead of relying on the currently systemwide installed composer.
Related Topics
Curl Error 60: Ssl Certificate in Laravel 5.4
Programmatically Creating New Order in Woocommerce
When Do I Use Static Variables/Functions in PHP
How to Return a Proper Success/Error Message for Jquery .Ajax() Using PHP
Laravel No Supported Encrypter Found. the Cipher And/Or Key Length Are Invalid
Fastest Hash for Non-Cryptographic Uses
How to Print SQL Statement in Codeigniter Model
Accessing Laravel .Env Variables in Blade
Dynamic Paypal Button Generation - Isn't It Very Insecure
MySQL and PHP - Insert Null Rather Than Empty String
How to Redirect Back to Form with Input - Laravel 5
Issues with PHP 5.3 and Sessions Folder
What Ocr Options Exist Beyond Tesseract
Forget Password Page, Creating a Generated Password to Email to the User