Resolving PHP Version Conflicts with Laravel Herd and XAMPP on Windows

By: Roel
July 1, 2024

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. 

The Problem

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.

  1. Edit System Environment Variables:
    • Open the Environment Variables window:
      • Press Win + Pause to open System Properties.
      • Click on Advanced system settings.
      • Click on Environment Variables.
    • In the Environment Variables window, I edited both the User variables for Roel and System variables sections to adjust the PATH.
  2. Adjust PATH Priorities:
    • In the Edit Environment Variable dialog, I moved C:\Users\Roel\.config\herd\bin to the top of the list, ensuring it was prioritized over C:\xampp\php.
  3. Restart Command Prompt:
    • To apply the changes, I closed all instances of the command prompt and reopened a new one.
  4. Verification:
    • Running php -v in the command prompt now correctly showed PHP 8.3, confirming that the system was using the PHP version provided by Laravel Herd.

 Additional Steps 

In some cases, you might need to take additional steps to ensure no lingering conflicts:

  • Remove or Rename Conflicting Executables: If issues persist, temporarily renaming the php.exe in the XAMPP directory can ensure no interference.
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

Conclusion

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.

Recommended Tutorials

If you want to learn more about Environment variables and how it works in your computer, I recommend watching this tutorial 

About the Author

Roel
Roel

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.



Please login to comment.

© 2024 Talldevelopers.com, All rights reserved.