In the world of PHP development, managing different PHP versions can be a common but frustrating issue, especially when using multiple development environments. Recently, I encountered a scenario where my local development setup was showing an incorrect PHP version, causing some confusion and hindering my development process. Here’s how I resolved the PHP version conflict between Laravel Herd and XAMPP on my Windows machine.
I installed Laravel Herd to streamline my Laravel development on Windows. However, when running php -v in my command prompt, it displayed PHP 8.1 instead of the PHP 8.3 version provided by Herd. This discrepancy was caused by the presence of XAMPP, which was also installed on my machine and using an older PHP version.
Identifying the Issue
To identify which PHP versions were being used and their locations, I used the where php command in the command prompt. This command lists all the instances of the PHP executable found in the system's PATH.
where php
The output showed two paths:
C:\xampp\php\php.exe C:\Users\Roel\.config\herd\bin\php.bat
To resolve the conflict and ensure the correct PHP version was used, I adjusted the system environment variables.
In some cases, you might need to take additional steps to ensure no lingering conflicts:
C:\xampp\php\php.exe -> C:\xampp\php\php8.1.exe
Check for Aliases or Scripts: Ensure no shell aliases or scripts override the php command
By adjusting the PATH environment variable and ensuring the correct PHP binary was prioritized, I successfully resolved the version conflict between Laravel Herd and XAMPP. This solution ensures that my development environment uses the intended PHP version, allowing me to continue my work without interruption.
Managing multiple PHP versions can be tricky, but with careful configuration of your environment variables, you can seamlessly switch between different setups and maintain a smooth development workflow. If you encounter similar issues, following these steps should help you resolve any conflicts and get your development environment back on track.
If you want to learn more about Environment variables and how it works in your computer, I recommend watching this tutorial
Hi, my name is Roel. I am a TALL stack developer. I created this site to document all web applications I created using the TALL stack. I exclusively built products using Laravel because I like the experience writing applications using the simplest framework/stack available.