DEV Community

Cover image for Multiple PHP version on Windows 10
Thodoris Kouleris
Thodoris Kouleris

Posted on

Multiple PHP version on Windows 10

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.

example 1

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

example 2

d. From the System variables, select Path and click Edit

example 3

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.

example 4

f. Click OK to close the window, and that's it. You have PHP8.2.8 as the default system PHP version

example 5

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)

Collapse
 
eimihar profile image
Rahimie Ahmad

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

Collapse
 
dzod profile image
dzodd

Thank you

Collapse
 
van4kk profile image
Ionuț - Nicu • Edited

damn mate, that's really a very good idea, and the command should be something like php82 -v ?

Collapse
 
erhanurgun profile image
Erhan ÜRGÜN

You can easily switch between php versions using Laragon or Herd!

SS: Laragon
Image description

SS: Herd

Image description

Collapse
 
abiruzzamanmolla profile image
Abiruzzaman Molla

but cann't access php's multiple version in command line!

Collapse
 
erhanurgun profile image
Erhan ÜRGÜN

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...

Image description

For Windows Powershell:

Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1
refreshenv
Enter fullscreen mode Exit fullscreen mode

Image description

If you don't want to write this command for ENV every time, then add it to $PROFILE and just use the last command refreshenv!

# Add Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1 to the file opened with this command
notepad $PROFILE

# Then do this again from the terminal
refreshenv
Enter fullscreen mode Exit fullscreen mode
Collapse
 
dimas_suryaprayitna_08a7 profile image
Dimas Surya Prayitna

thank you dear