A very common problem that many PHP developers have is how to get multiple PHP version to run on the same computer. So, here is a solution.
Let's say that you already have installed PHP 7.4 on your computer, but you have to work on a project that needs PHP 8.2 to run. First head to https://windows.php.net/download/ where you can find the version that we are interested.
Find the version 8.2.8 and click on zip hyperlink to start downloading. Once the file is downloaded, create a folder in the path where your current PHP version is installed. For example, if you have installed your current PHP in C:\PHP\7.4 create a folder C:\PHP\8.2.8 and unzip the content of the zip file in that folder.
Now, you have both versions on your computer. Now, you have 2 options. Whether you will make the PHP8.2.8 your default version or using it every time you want to work with your new project.
Make PHP8.2.8 the default PHP
In order to make the new PHP the default system PHP version, you follow the next steps.
a. Open a command line
b. Type SystemPropertiesAdvanced
c. Go to Environment Variables
d. From the System variables, select Path and click Edit
e. Click new and add the path of your new PHP version. After that click, Move Up as many times you need so that path will be on top of the other PHP versions that you have.
f. Click OK to close the window, and that's it. You have PHP8.2.8 as the default system PHP version
Use it when you need it
The second option, if you don't want to make PHP8.2.8 your current version, is to use it only when you need it. So, let's say that you have a script that runs with older version. Open a command prompt and type the full path of the PHP version that you want to use, i.e. c\PHP\7.4\php myscript.php
Top comments (7)
another method that i use is to rename the php.exe to php82.exe, so you dont have to keep juggling between multiple php version through env variable order
Thank you
damn mate, that's really a very good idea, and the command should be something like
php82 -v
?You can easily switch between php versions using Laragon or Herd!
SS: Laragon
SS: Herd
but cann't access php's multiple version in command line!
After changing the PHP version, you need to add it to the PATH and then update the ENV with the terminal or terminate the session and start a new session...
For Windows Powershell:
If you don't want to write this command for ENV every time, then add it to
$PROFILE
and just use the last commandrefreshenv
!thank you dear