Composer change php version linux

How to change PHP version used by composer

Whenever I choose PHP 7 from the control panel of WAMP and then run php -v it still printing PHP5.6 (CLI). instead of PHP7 .

How can I use PHP7 without reinstalling the composer again?

@Tofandel. The OP (Original Poster) reference WAMP, which stands for Windows, Apache, MySQL and PHP. If you need a LAMP solution (Linux, Apache, MySQL and PHP) then you would need to reference your chosen LAMP software documentation and any associated workaround(s).

17 Answers 17

You can change php version of composer without uninstalling it, follow these steps :

  1. Search for system environment variables in cortana.
  2. Click on the button «Environment variables».
  3. Under «System variables» select path and click on edit, you will see one entry like this «C:\wamp\bin\php\php5.6.13».
  4. Just change this to the folder name of the php located at your wamp/bin/php7.1.9, here php7.1.9 is folder name.
  5. Replace php5.6.13 with bin7.1.9, it will look like these «C:\wamp\bin\php\php7.1.9», just click ok on all the boxes.
  6. You are done.
  7. To verify, first close all the cmd windows, than open cmd and type php -v , press enter and you should see php7.1.9.
  8. If you don’t see change in php version than just restart your pc and run php -v again in cmd , it will work.

this works BUT the wamp server says it has an error and that it has detected a change in environment variables.

If wamp server shows error about change detection in environment variables I suggest you to restart server. If it does not solve than shutoff server and than start it again. If that also does not work than I suggest you to restart your pc. Hope it helps 🙂

Regarding step 3, for me it was under «User variables» not «System variables». But everything else worked 😄

You can use multiple php version like stackoverflow.com/questions/15617515/… and then you just need to change move up version as per your requirement

I’m assuming Windows if you’re using WAMP. Composer likely is just using the PHP set in your path: How to access PHP with the Command Line on Windows?

You should be able to change the path to PHP using the same instructions.

Читайте также:  Открыть архив линукс tar

Otherwise, composer is just a PHAR file, you can download the PHAR and execute it using any PHP:

C:\full\path\to\php.exe C:\full\path\to\composer.phar install 

What is the use of this line C:\full\path\to\php.exe C:\full\path\to\composer.phar install . I already have the composer.phar file since I’m already using composer in my current project

Composer phar example is golden! Finnaly got it working, no need of endless enviroment variables switching. Tnx much!

For Linux/MacOS users, would be something like: /Applications/MAMP/bin/php/php7.2.14/bin/php /usr/local/bin/composer install

If anyone is still having trouble, remember you can run composer with any php version that you have installed e.g. $ php7.3 -f /usr/local/bin/composer update

Use which composer command to help locate the composer executable.

I found a very easy way to switch php versions:

  • Search for system environment variable
  • Click on «Environment variables»
  • Under «System variables» select path and click on edit
  • Move the PHP version folder you want to use before the other one. So for example: php 7.0 will now be used:

enter image description here

enter image description here

  • Close all windows by clicking «OK»
  • Close all the cmd windows, than open cmd and type php -v
  • You will see the correct php version loaded now:

geeky talks about changing folder names, but I found that just changing the order of the folders is enough, since you maybe want to change back. This makes it much simpeler and better managable in my opinion.

After you change your environment variables, execute the “refreshenv” command. — You must have the Chocolatey package Installed. — The environment variables will be refreshed immediately, without the need to restart the computer, or sign out and without disrupting the workflow.

Another possibility to make composer think you’re using the correct version of PHP is to add to the config section of a composer.json file a platform option, like this:

Where is the PHP version of your choice.

Lets you fake platform packages (PHP and extensions) so that you can emulate a production env or define your target platform in the config. Example: .

enter image description here

This is what happens in my case. I hope this may help to someone have same situation. I’m using macOS Monterey with MAMP.

I linked the php 7.4 using ~/.profile file. So the terminal it says I’m using php 7.4. However, still my composer giving an error saying i’m using php 7.3.

So I check the php path using

This gives me the /usr/local/bin/php as my php cli location. So I remove the file and made a symlink to my php7.4 and now working perfectly.

sudo rm -rf /usr/local/bin/php sudo ln -s /Applications/MAMP/bin/php/php7.4.21/bin/php /usr/local/bin/php 

I found out that composer runs with the php-version /usr/bin/env finds first in $PATH, which is 7.1.33 in my case on MacOs. So shifting mamp’s php to the beginning helped me here.

PHPVER=$(/usr/libexec/PlistBuddy -c "print phpVersion" ~/Library/Preferences/de.appsolute.mamppro.plist) export PATH=/Applications/MAMP/bin/php/php$/bin:$PATH 

Old question I know, but just to add some additional information:

  • WAMP is used only on Microsoft Windows Operating Systems.
  • Changing the version of PHP used through the left-click -> PHP -> Version menu changes the version used by Apache to server your site.
  • Changing the version of PHP used through the right-click -> Tools -> Change PHP CLI Version menu changes the version used by WAMP’s PHP CLI.
Читайте также:  Дэвид тейнсли linux unix

Note: It is important to understand that the «PHP CLI Version» is used by WAMP’s own internal PHP scripts. This «PHP CLI Version» has nothing to do with the version you wish to use for your scripts, Composer or anything else.

For your scripts to work with the version you require, you need to add it’s path to the Users Environmental Path. You could add it to the Systems environmental Path but the Users Path is the recommended option.

From WAMP v3.1.2, it would display an error when it detect reference to a PHP path in the System or User Environmental Path. This was to stop confusion such as you were experiencing. Since v3.1.7 the display of this error can now be optionally displayed through a selection in the WampSettings menu.

As indicated in previous answers, adding an installed PHP path (such as «C:\wamp64\bin\php\php7.2.30») to the Users Environmental Path is the correct approach. PS: As the value of the Users Environmental Path is a string, all paths added must be separated with a semi-colon (;)

After experiencing the exact same problem (IE: Choosing which version of PHP I wanted Composer to use), I created a script which could easily and rapidly switch between PHP CLI Versions depending on what project I was working on.

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Читайте также:  Линукс защита от копирования

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change php version? #3537

change php version? #3537

Comments

I’m sorry to both you with a support question in the tickets here. I don’t know where else to ask. I’m not really that good at understanding CLI stuff — I’m a php guy.

So a long time ago, I installed and have been happily using composer on my mac. At the time I installed it, I followed some additional instructions I found online in order to get it so that when I want to use it, I just type

but I am now running several instances of PHP on my machine: I use MAMP PRO to change versions when I need. I assume that composer is using php from some source on my machine — and likely the one that ships with the OS — not the one I am actually using in MAMP.

I’ve looked for an alias setting or something somewhere that tells me how I am using composer without typing

but I can’t find anything — I have no .bash_profile file. I have no alias setting in my .tcshrc file.

so, how does composer know which php instance to use and how do I change it? (or is it not using php?)

The text was updated successfully, but these errors were encountered:

Источник

Composer does not detect php7 instead it uses 5.6. How can I set the CLI to use php7

enter image description here

Here when I execute php -v , it says it has php7
but when I try to execute composer update the response it

Your requirements could not be resolved to an installable set of packages. Problem 1 - This package requires php >=7.0.0 but your PHP version (5.6.33) does not satisfy that requirement. 

How can I fix this? NOTE : I’m not allowed to uninstall previous version of php Here is the composer.json

< "name": "laravel/laravel", "description": "The Laravel Framework.", "keywords": ["framework", "laravel"], "license": "MIT", "type": "project", "require": < "php": ">=7.0.0", "fideloper/proxy": "~3.3", "intervention/image": "^2.4", "laravel/framework": "5.5.*", "laravel/passport": "^v1", "laravel/tinker": "~1.0" >, "require-dev": < "filp/whoops": "~2.0", "fzaninotto/faker": "~1.4", "mockery/mockery": "0.9.*", "phpunit/phpunit": "~6.0" >, "autoload": < "classmap": [ "database/seeds", "database/factories" ], "psr-4": < "App\\": "app/" >, "files": [ "app/Helpers/misc.php" ] >, "autoload-dev": < "psr-4": < "Tests\\": "tests/" >>, "extra": < "laravel": < "dont-discover": [ ] >>, "scripts": < "post-root-package-install": [ "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" ], "post-create-project-cmd": [ "@php artisan key:generate" ], "post-autoload-dump": [ "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", "@php artisan package:discover" ] >, "config": < "preferred-install": "dist", "sort-packages": true, "optimize-autoloader": true >> 
composer update --ignore-platform-reqs 

Источник

Оцените статью
Adblock
detector