How to specify to use a specific PHP version when running composer install?
There is more than one issue here.
First, you most likely don't really need to tell composer
to use one interpreter or another. If you know that the platform requirements are going to be correct at runtime, but the runtime executable is not the same than the install
executable, you can simply say:
composer install --ignore-platform-reqs
This way composer won't check that the runtime and extensions match what you declared on composer.json
(but you'll need to make sure that these requirements are fulfilled on the server where the project actually runs).
But if you really want to execute composer with a different runtime...
composer
uses shebang + env
to determine which PHP executable is going to use.
Basically it uses #!/usr/bin/env php
to find which php
executable is available, same as you were doing.
If you want to use a different executable, you just need to be explicit about it.
E.g. if your PHP 7.2 is installed at /usr/bin/php7.2
and composer at /usr/local/bin/composer
, you just need to do:
# /usr/bin/php7.2 /usr/local/bin/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
Tell composer which PHP version to use
Yes, you just have to specify which PHP version to use by directly calling the intended PHP bin file.
So, instead of
php composer.phar update
You have to use something like
/path/to/php5.6/bin/php composer.phar update
In my case, on a CentOS server with Plesk (default PHP version was 5.4, but I also had 5.6 and 7.0 installed), I had to use :
/opt/plesk/php/5.6/bin/php composer.phar update
Calling Composer With Specific PHP Version on Homestead
Run the command php70
and that will set PHP 7.0 to the default system version of PHP, then you can run composer
normally.
How to switch between two different php version with composer
Create a Windows batch file that calls the composer.phar file using the php7 binary. Let's call the file composer7.bat:
@echo OFF
:: in case DelayedExpansion is on and a path contains !
setlocal DISABLEDELAYEDEXPANSION
c:\path\to\php7\directory\php.exe "%~dp0composer.phar" %*
Save the file along with the originally installed composer.bat file, mine is located in C:\ProgramData\ComposerSetup\bin\ directory.
Now call the php7 composer with the new command:
composer7 require ...
php version mismatch with composer
Your cli php version (the one you are using for your composer install
) and the php version your apache is running in your server (the one you see in your phpinfo()
page) might not match.
Try running this in your console:
$ php -v
This would output the version you are actually using when running your composer install
To run the same version in your server, you might need to locate the PHP 7 binary on your machine (maybe /usr/bin/php7.3
, you could try to execute a $ whereis php
), then:
/usr/bin/php7.3 /usr/local/bin/composer install
This was assuming that your composer binary is under /user/local/bin/composer
, modify as need.
Composer uses wrong php version, but php -v shows the correct one (Ubuntu)
try this:
composer install --ignore-platform-reqs
or this in composer.json
"config": {
"preferred-install": "dist",
"platform": {
"php": "7.0.0"
}
}
in the second solution basically you're faking a platform, and run composer.phar update
after this
Related Topics
Regex to Check the String Contains Only Letter and Numbers But Not Only Numbers
Curl (7): Failed to Connect to Localhost Port 8000: Connection Refused
Dompdf Not Rendering Images from the Server But Is Rendering from External Source
Creating Advanced Search Query With PHP Mysqli
How to Use Find in Set for User Rankings Based on Score
Using Maatwebsite Excel 3.1 Export How to Set Background Color for Cells and Font Size for Heading
Auto Update Cart on Click in Woocommerce
How to Sort Arrays and Data in PHP
Returning Json from a PHP Script
Php to View Pdf on Web Page and Disable User to Download
How to Convert a 13 Digit Unix Timestamp to Date and Time
Success Message Pop-Up After from Submit Button Clicked
Laravel: Pdoexception: Could Not Find Driver
Laravel Eloquent Get Results Grouped by Days