Initialize-PhpSwitcher : not a junktion
ltdeta opened this issue · comments
Why does the following error occur?
Remove-PhpSwitcher
Initialize-PhpSwitcher D:\PHP7
D:\PHP7 already exist and it's not a junction.
In C:\Program Files\WindowsPowerShell\Modules\PhpManager\1.24.4\public\Initialize-PhpSwitcher.ps1:54 Zeichen:17
throw "$Alias already exist and it's not a junction."
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : OperationStopped: (D:\PHP7 already...not a junction.:String) [], RuntimeException
FullyQualifiedErrorId : D:\PHP7 already exist and it's not a junction.
Is D:\PHP7
an existing directory?
yes, i have already installed two versions (D:\Php7 and D.\php7-nts)
Now I just want to install the imagick extension
yes, i have already installed two versions (D:\Php7 and D.\php7-nts)
Here's what I'd do:
Initialize-PhpSwitcher D:\php
Add-PhpToSwitcher ts D:\Php7
Add-PhpToSwitcher nts D:\php7-nts
Next, to have D:\php pointing to D:\Php7:
Switch-Php ts
To have D:\php pointing to D:\php7-nts:
Switch-Php nts
And, to install imagick, you simply have to write
Install-PhpExtension imagick
I have done the following without errors:
Initialize-PhpSwitcher D:\php
Add-PhpToSwitcher ts D:\Php7
Add-PhpToSwitcher nts D:\php7-nts
get-php:
Folder : D:\php7-nts
ExecutablePath : D:\php7-nts\php.exe
ExtensionsPath : d:\php7-nts\ext
ApiVersion : 20190902
MajorMinorVersion : 7.4
Version : 7.4.19
FullVersion : 7.4.19
UnstabilityLevel :
UnstabilityVersion :
DisplayName : PHP 7.4.19 x64 (64-bit) Non-Thread-Safe
Architecture : x64
ThreadSafe : False
VCVersion : 15
When executing the command Switch-Php ts
, the following error message now appears
PHP is currently available in the following directories:
D:\php7-nts
PHP Switcher is meant to have PHP in PATH only as D:\php
You can override this behavior by calling Switch-Php with the -Force flag.
In C:\Program Files\WindowsPowerShell\Modules\PhpManager\1.24.4\public\Switch-Php.ps1:68 Zeichen:17
... throw ("PHP is currently available in the following direc ...
CategoryInfo : OperationStopped: (PHP is currentl...he -Force flag.:String) [], RuntimeException
FullyQualifiedErrorId : PHP is currently available in the following directories:
D:\php7-nts
PHP Switcher is meant to have PHP in PATH only as D:\php
You can override this behavior by calling Switch-Php with the -Force flag.
Switch-Php ts -force
get-php
Folder : D:\php7-nts
ExecutablePath : D:\php7-nts\php.exe
ExtensionsPath : d:\php7-nts\ext
ApiVersion : 20190902
MajorMinorVersion : 7.4
Version : 7.4.19
FullVersion : 7.4.19
UnstabilityLevel :
UnstabilityVersion :
DisplayName : PHP 7.4.19 x64 (64-bit) Non-Thread-Safe
Architecture : x64
ThreadSafe : False
VCVersion : 15
Folder : D:\php
ExecutablePath : D:\php\php.exe
ExtensionsPath : d:\php7\ext
ApiVersion : 20190902
MajorMinorVersion : 7.4
Version : 7.4.19
FullVersion : 7.4.19
UnstabilityLevel :
UnstabilityVersion :
DisplayName : PHP 7.4.19 x64 (64-bit) Thread-Safe
Architecture : x64
ThreadSafe : True
VCVersion : 15
I have nothing more to add to what the error message says:
PHP is currently available in the following directories:
D:\php7-nts
PHP Switcher is meant to have PHP in PATH only as D:\php
So, you should remove D:\php7-nts from your PATH environment variable
Hello all, I am also having this problem. I have PHP installed in the path C:\laragon\bin\php\php8.1
and I have also set this path in the environment variables. When I run the command Initialize-PhpSwitcher C:\laragon\bin\php\php8.1
I get the error $Alias already exist and it's not a junction.
Could you please help resolve this?
THe usage of the PHP Switcher is well described in the README file.
You need to invoke Initialize-PhpSwitcher
passing it the path to a non existing directory.
This command will create a new symlinked directory at that path: as you can see from your error message, C:\laragon\bin\php\php8.1
already exists: that's why it fails.
For example, if you have two PHP versions available at:
C:\laragon\bin\php\php8.1
C:\laragon\bin\php\php8.2
You have to
- call
Initialize-PhpSwitcher -Alias C:\laragon\bin\php\php -Scope CurrentUser
- add
C:\laragon\bin\php\php
to thePATH
environment variable (and remove from it any other folder containing PHP) - add the two PHP versions to the PHP Switcher:
Add-PhpToSwitcher -Name 8.1 -Path C:\laragon\bin\php\php8.1
Add-PhpToSwitcher -Name 8.2 -Path C:\laragon\bin\php\php8.2
That way, you can switch the current PHP version (that is, the one in the PATH), simply by running Switch-Php 8.1
or Switch-Php 8.2
Awesome @mlocati, my understanding of the README.md line Then you initialize the PHP Switcher, specifying where the current PHP version should be available: was the directory of your current PHP version which in my case was C:\laragon\bin\php\php8.1
hence the error but you have clarified this well. Thank you.