1

I have installed on Windows 10, both php 7.4 and php 8.1 in different folders PHP7 and PHP8. I have put C:/PHP7 in the PATH (environment variable) and now when I type php in the terminal (CMD, PowerShell and Git Bash) is running php7.

For php8 I have made a custom command php8 by creating a php8.cmd file with this simple content:

"C:/PHP8/php.exe"  %*

I have placed the folder where the file is located in the PATH.

All good. Now when I type php8 in Command Line or PowerShell is running php 8. But if i type php8 in the Git Bash it says bash: php8: command not found

Somehow the Git Bash for Windows does not see the new custom command. I am not sure if I need to make a separate .sh file in which to put the equivalent content from the php8.cmd file or if is just a problem of configuring Git Bash to see the php8.cmd file.

Also I do not know what is the equivalent of "C:/PHP8/php.exe" %* in shell script.

Can anyone help with this?

I am doing this because I have an application based on Laravel8 (using php 7.4) and I want to switch it on Laravel 9 (which requires php 8). So I want to start a separate folder where to test the application using Laravel 9 (to see which changes I need to make to the code base or which dependencies need to upgrade). In my PhpStorm I am using Git Bash as the integrated terminal, and that's why I want that custom command php8 to work in Git Bash, too.

Many thanks!

Ulrich Eckhardt
  • 16,572
  • 3
  • 28
  • 55
LTanase
  • 197
  • 2
  • 15
  • 1
    Does this answer your question? [Git Bash doesn't see my PATH](https://stackoverflow.com/questions/10681101/git-bash-doesnt-see-my-path) – Jonathan Jan 29 '23 at 03:25
  • 1
    I made it work by placing in .bash_profile file an alias command like this php8=/path/to/php8 executable. Now I can run php8 artisan commands using PHP 8. Still had a problem with composer update (which used the default PHP 7) but I run the command with -- ignore-platform-reqs flag and now my application runs on Laravel 9 – LTanase Jan 29 '23 at 14:27
  • Great you found a solution! I added this as an answer with additional details, so others can benefit from your solution, if you accept it. :) – Jonathan Jan 29 '23 at 15:27

1 Answers1

0

Add the path to your php8 binaries (executables on Windows) to your environment.

On Linux
For example add php8=/usr/bin/php8 alias to .bash_profile (if using bash) on Linux. You can find out the path by running which php in the shell.

On Windows
Find out the executable's path by running where php.exe in the Terminal/PS. Then add this path to the user's PATH variable in system settings.


You should then be able to use php8 to run php commands in php8.

Also ensure composer uses the correct php version either by adding --ignore-platform-reqs argument or setting the following in composer.json

"config": {
    "platform": {
        "php": "8.0.0"
    }
}
Jonathan
  • 1,955
  • 5
  • 30
  • 50