Configuring Local Environment to Support Multiple PHP Versions in Windows

Abysim
1 min readAug 15, 2024

--

I immediately developed the previous application I built on production, as it was a small personal API app. However, when I decided to recreate my website, I chose a local system, which allowed me to experiment and freely work with new things.

My chosen local hosting solution was the most recent version of XAMPP, incorporating PHP 8.2. While this isn’t the latest PHP 8.3, it’s adequately efficient for development. It also offers the possibility to upgrade PHP if the need arises manually. Still, I need a different PHP version for my work in the system PATH variable.

Given that most course instructors typically employ aliases for PHP and Laravel Artisan Console, I created similar aliases in PowerShell:

Set-Alias p D:\xampp\php\php
function runArtisanCommand { p artisan @args }
Set-Alias pa runArtisanCommand

Setting these aliases was challenging as it necessitated creating a function in PowerShell that facilitated passing parameters to an aliases. Now, I can swiftly access PHP using the p command and execute artisan in the relevant folder via the pa command.

To avoid repeatedly generating these aliases, I incorporated them into the PowerShell profile script using the command:

notepad $PROFILE.AllUsersAllHosts

Since my system doesn’t operate on server Windows, I had to authorize the execution of scripts in PowerShell under administrator using the command:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

This article will be a helpful reference for me when I occasionally need to replicate these setups on different systems in the future.

--

--

Abysim

Team lead, web developer, support product owner and engineer, photo amateur, gamer, fan of TV shows and big cats.