Configuring Local Environment to Support Multiple PHP Versions in Windows
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, with PHP 8.2. While this isn’t the latest PHP 8.3, it’s good enough for development. And you can still upgrade PHP manually if needed. Still, I need a different PHP version for my work in the system PATH variable.
Since most course instructors use aliases for PHP and the Laravel Artisan console, I set up similar ones in PowerShell:
Set-Alias p D:\xampp\php\phpfunction runArtisanCommand { p artisan @args }Set-Alias pa runArtisanCommand
Setting these aliases was challenging because it required a PowerShell function to pass parameters to the alias. Now I can call PHP quickly with the p command and run artisan in the relevant folder with the pa command.
To avoid repeatedly generating these aliases, I added them to the PowerShell profile script using the command:
notepad $PROFILE.AllUsersAllHosts
Since my machine doesn’t run Windows Server, I had to allow scripts to run in PowerShell as administrator with 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.