简体   繁体   English

Git Bash 对于 Windows 没有看到自定义命令 php8

[英]Git Bash for Windows does not see custom command php8

I have installed on Windows 10, both php 7.4 and php 8.1 in different folders PHP7 and PHP8.我已经在 Windows 10、php 7.4 和 php 8.1 上安装在不同的文件夹 PHP7 和 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.我已将 C:/PHP7 放入 PATH(环境变量)中,现在当我在终端(CMD、PowerShell 和 Git Bash)中键入 php 时,正在运行 php7。

For php8 I have made a custom command php8 by creating a php8.cmd file with this simple content:对于 php8,我通过创建一个包含以下简单内容的php8.cmd文件来制作自定义命令php8

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

I have placed the folder where the file is located in the PATH.我已经把文件所在的文件夹放在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现在,当我在命令行中键入 php8 或 PowerShell 正在运行时 php 8。但是如果我在 Git Bash 中键入 php8,它会bash: php8: command not found

Somehow the Git Bash for Windows does not see the new custom command.不知何故 Git Bash 为 Windows 没有看到新的自定义命令。 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.我不确定我是否需要制作一个单独的.sh文件来放置php8.cmd文件中的等效内容,或者是否只是配置 Git Bash 以查看php8.cmd文件的问题。

Also I do not know what is the equivalent of "C:/PHP8/php.exe" %* in shell script.我也不知道 shell 脚本中的"C:/PHP8/php.exe" %*是什么。

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).我这样做是因为我有一个基于 Laravel8 的应用程序(使用 php 7.4),我想将其打开 Laravel 9(需要 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).所以我想启动一个单独的文件夹,在其中使用 Laravel 9 测试应用程序(以查看我需要对代码库进行哪些更改或哪些依赖项需要升级)。 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.在我的 PhpStorm 中,我使用 Git Bash 作为集成终端,这就是为什么我希望自定义命令 php8 也能在 Git Bash 中工作。

Many thanks!非常感谢!

Add the path to your php8 binaries (executables on Windows) to your environment.将 php8 二进制文件(Windows 上的可执行文件)的路径添加到您的环境中。

On Linux在 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.例如,在php8=/usr/bin/php8别名添加到.bash_profile (如果使用 bash)。您可以通过运行which php中的 which php 找到路径。

On Windows在 Windows
Find out the executable's path by running where php.exe in the Terminal/PS.通过在终端/PS 中运行where php.exe找出可执行文件的路径。 Then add this path to the user's PATH variable in system settings.然后在系统设置中将此路径添加到用户的PATH变量中。


You should then be able to use php8 to run php commands in php8.然后您应该能够使用php8在 php8 中运行 php 命令。

Also ensure composer uses the correct php version either by adding --ignore-platform-reqs argument or setting the following in composer.json还要确保作曲家使用正确的 php 版本,方法是添加--ignore-platform-reqs参数或在composer.json中设置以下内容

"config": {
    "platform": {
        "php": "8.0.0"
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM