I am trying to run a seed command for an application but windows power shell runs it with PHP 5, when the app is running on PHP 7. I need it to run that one command assuming php as version 7, that is, without changing the version of PHP powershell is using permanently.
I have tried all the solutions I’ve managed to find online, but unfortunately the majority of them are targeted to Linux systems, not windows.
This includes:
- editing composer.json/lock;
- defining an alias of php pointing to the path of the version 7 and using it to run the command;
- altering the PHP version using PHP manager in IIS
Among others.
Is this a possible thing to do? No matter what I do, my seed command always assumes php5 as the one to use, which results in several “syntax” errors namely complaining about the double question mark “??” null syntax only introduced in PHP 7.
4
Answers
The way I solved it was by adding in my script files "set PATH=C:Program FilesPHPv7.0" before the instructions.
Also needed to add in my environment variables the parameters to accept CMD commands in Powershell.
This was my script file:
First of all you must have php 7 installed.
Then in windows:
You could use different version of PHP in IIS side by side.
IIS support to specify different version PHP-CGI.exe for each sub-application or folder by following steps.
https://learn.microsoft.com/en-us/iis/application-frameworks/install-and-configure-php-applications-on-iis/using-fastcgi-to-host-php-applications-on-iis
You could map PHP5 as global Version and create a sub-application to handle the specific Powershell script, then set module mapping to PHP 7 for this sub-application’s handler.
So that the specific page with PHP 7 will not interfere global application.
Consider we have
"C:php"
directory which includes 3 sub-directories for 3 version of php:"C:php56"
,"C:php74"
and"C:php81"
.notepad $PROFILE
command to open your PowerShell profile in Notepad.Run
Set-PHPVersion 56
,Set-PHPVersion 74
orSet-PHPVersion 81
to use the version you want.