简体   繁体   English

Windows PATH 变量不适用于 Composer

[英]Windows PATH variable not working for Composer

I've installed Composer on Windows 10 using installer, but it doesn't seem to work properly.我已经使用安装程序在 Windows 10 上安装了 Composer,但它似乎无法正常工作。 When I try running composer in the console, it throws an error:当我尝试在控制台中运行composer时,它会抛出一个错误:

'""' is not recognized as an internal or external command,
operable program or batch file.

I rebooted my pc twice, run the console as an administrator and checked the PATH variable.我重新启动了我的电脑两次,以管理员身份运行控制台并检查了 PATH 变量。 It contained the Composer install path ( C:\ProgramData\ComposerSetup\bin ), but for some reason it doesn't work.它包含 Composer 安装路径( C:\ProgramData\ComposerSetup\bin ),但由于某种原因它不起作用。 I tried running the composer directly after cd to this folder, and it worked, but it doesn't work otherwise.我尝试在 cd 到这个文件夹之后直接运行作曲家,它可以工作,但它不能正常工作。

'where composer' prints out the following: “作曲家”打印出以下内容:

C:\OpenServer\modules\php\PHP_7.4\composer.bat
C:\ProgramData\ComposerSetup\bin\composer
C:\ProgramData\ComposerSetup\bin\composer.bat

The first path refers to the folder where the PHP is installed, the second is the executable itself第一个路径是指安装PHP的文件夹,第二个是可执行文件本身

If I try to run 'C:\ProgramData\ComposerSetup\bin\composer', it works as intended, so the Composer itself is installed correctly如果我尝试运行“C:\ProgramData\ComposerSetup\bin\composer”,它会按预期工作,因此 Composer 本身已正确安装

How do I get the PATH variable for Composer work properly?如何让 Composer 的 PATH 变量正常工作?

I deleted the C:\OpenServer\modules\php\PHP_7.4\composer.bat file, and it worked fine.我删除了C:\OpenServer\modules\php\PHP_7.4\composer.bat文件,它工作正常。

This folder is the PHP installation folder, which came packed with a local server that I installed previously.这个文件夹是 PHP 安装文件夹,它包含我之前安装的本地服务器。 For some reason, it had a broken composer.bat , and when I was installing Composer, I checked "Add PHP folder to the PATH variable".出于某种原因,它有一个损坏的composer.bat ,当我安装 Composer 时,我检查了“将 PHP 文件夹添加到 PATH 变量”。 That is why when I tried to run composer , it ran the broken file and was throwing a weird error.这就是为什么当我尝试运行composer时,它运行了损坏的文件并抛出了一个奇怪的错误。

Thank you, Álvaro González, for helping me to figure that out!谢谢你,Álvaro González,帮助我解决这个问题!

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

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