34

I am using windows server 2008 os. i download composer setup.exe and install to my PC . when I try composer install . I getting an error:

'composer' is not recognized as an internal or external command,

eg:-

c:\xampp\htdocs\shop>composer install
'composer' is not recognized as an internal or external command,
operable program or batch file.

My environment variable PATH is shown below:

C:\xampp\php\;C:\Users\Administrator\AppData\Roaming\Composer\vendor\bin
Markus Müller
  • 2,611
  • 1
  • 17
  • 25
danish dani
  • 603
  • 2
  • 8
  • 16

13 Answers13

60

For anyone coming here from Google who are facing the same issue. I just managed to solve this issue after all the other "solutions" other people suggested didn't work.

I installed Composer properly and the Environment variable was set but it just wouldn't work.

In my case composer is installed in C:\ProgramData\ComposerSetup\bin and this is exactly what is in my PATH Environment variable. After messing around a bit trying to fix it I saw that under System variables under PATH there is something called PATHEXT I opened that and added ;.PHAR to the end of it. So it ended up like this:

enter image description here

And this is what my PATH is now: enter image description here

I closed all file explorer windows and command prompts and started a new CMD and ran composer --version and it worked!

I hope this helps someone facing the same issue as me.

Mahan_F
  • 7,839
  • 2
  • 14
  • 26
  • 1
    this worked! Just curious, why do we need to add `;.PHAR` to the `PATHTEXT`? – indago Aug 13 '18 at 19:06
  • @indago I can't be certain since I got this fixed by just randomly messing around but the reason I thought about adding .PHAR is that there is a Composer.phar inside the composer directory that I believe is what runs when you use composer commands , so when I saw that it's not there I added it and it immediately fixed the issue. Glad you got it sorted as well! – Mahan_F Aug 13 '18 at 19:33
  • 2
    for me just restarting cmd (as admin) was enough – Tadas V. Oct 31 '18 at 22:23
  • thanks, that's the exact problem i got after installing on Windows 11 – Rusher Oct 09 '21 at 23:48
  • 1
    the other thing i realize is that path to composer must be **higher** in list, than path to php. hope this will help someone. – Rusher Oct 09 '21 at 23:56
  • I was using it in VSCODE and I had to close it once and open again to work – Ali Samie Feb 26 '23 at 13:57
  • Fixed it for me on a Windows 11 laptop, thank you – 4532066 Apr 08 '23 at 12:14
22

https://getcomposer.org/doc/00-intro.md#installation-windows

Close your current terminal and open a new one.

Furquan
  • 1,542
  • 16
  • 20
  • You do not need to restart your computed, simply close your current terminal and open a new one. –  Jan 18 '18 at 23:20
17

I had the same problem, I kept repeating the composer installation until it was resolved this way:

1) Download the composer installer (.exe) and put it on C:/XAMPP.

2) Run the installer by just clicking next till the end.

3) Open command-line (cmd) and cd to your project directory (C:/XAMPP/htdocs/myproject) and type composer and see if you have it installed.

4) It should work now, let's say you want to install a PHP framework from your project directory: cmd=>composer require slim/slim "^3.0".

Satan Pandeya
  • 3,747
  • 4
  • 27
  • 53
amin
  • 171
  • 1
  • 4
9

I had the same problem . In my case i used the command "php composer.phar " instead of "Composer " and it worked .

5

just paste " echo @php "%~dp0composer.phar" %*>composer.bat " This in your Terminal where you install composer and Boom you get the solution.

Punit khandelwal
  • 129
  • 1
  • 13
1

The solution is to use complete composer path instead of composer install eg:- C:\ProgramData\ComposerSetup\bin\composer install" instead of "composer install

Better still, add "C:\ProgramData\ComposerSetup\bin\" to your environment variables, so that you can use "composer install".

danish dani
  • 603
  • 2
  • 8
  • 16
0
If u can't find composer file than follow only 2 steps
1- Download composer file from [https://getcomposer.org/download/]<click on Composer-Setup.exe>

2- Install above file at your project root dir. and give second path is your php.exe file and finally solve this issue.
Yagnesh bhalala
  • 1,107
  • 1
  • 15
  • 17
0

Simply use like this

C:\jay\xampp\htdocs\zoho1>php composer.phar require zohocrm/php-sdk

Jay Bharat
  • 691
  • 7
  • 6
0

You Just Don't need to worry about this if you have installed composer using Command-line installation than this problem will occurs.

So my suggestion is to download .exe file by visiting this link https://getcomposer.org/

And also after download using this link you don't need to use php composer.phar instead of composer only

0

I was facing the same issue in installing the composer command in cmd but when I closed all windows file explorers and again run this command "composer global require laravel/installer " from "**https://laravel.com/docs/8.x**". It just installed without any error

0

remove all your playings with composer path in path variable go to https://getcomposer.org/doc/00-intro.md#using-the-installer

and find Composer-Setup.exe link to that exe.

CodeToLife
  • 3,672
  • 2
  • 41
  • 29
0

I had the same problem on Windows. Similar to Punit khandelwal's answer.

  1. Download and run composer setup

  2. Copy composer.phar to c:/composer/composer.phar

  3. Create a new file c:/composer/composer.bat with:

    @ECHO OFF php "c:/composer/composer.phar" %*

  4. Add c:/composer/ to your system Path environment variable

  5. Add .PHAR to your system PATHEXT environment variable (below the Path variable)

  6. Close & reopen your VS Code/CMD/Power Shell

You can now run composer commands from the command line on Windows without receiving the message:

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

Steve
  • 2,066
  • 13
  • 60
  • 115
-2

I can solve this problem easily without do anything.

Suppose I'm going to create a project in my desktop and facing the problem which you have shown in the description. now follow the step.

Project folder on desktop

Project folder on desktop

Step 1: go you your CMD(Command Prompt) of your Computer

command canvas

step 2:Select the folder by command here like image (cd/desktop/example folder)

Select the folder on CMD

Step 3: After select the folder now write the command which you want to do like screenshot . you can see Im writing the command for laravel.

composer command

done, just easy step you can work anything from here and you can see downloading and being prepare for the project

https://i.stack.imgur.com/2T34i.png

https://i.stack.imgur.com/1kcDP.png

ChristianYami
  • 586
  • 1
  • 9
  • 17