Is there a way to install Composer globally on Windows?

I read the global installation documentation for Composer, but only for * nix systems:

curl -s https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer 

I would be so happy to do the same on Windows as the OS of my development machine. I could run

 composer update 

From any folder where composer.json exists. The php.exe interpreter php.exe already in the PATH variable.

Any clue?

+44
windows php composer-php
Aug 21 '12 at 16:40
source share
10 answers

Sure. Just put composer.phar somewhere like C:\php\composer.phar , then create a batch file somewhere in PATH called composer.bat that does the following:

 @ECHO OFF php "%~dp0composer.phar" %* 

"% *" repeats all the arguments passed to the shell script.

Then you can run composer update whatever you want!

+65
Aug 21 2018-12-18T00:
source share

Install composer

On Windows, you can use Composer Windows Installer .

+16
Mar 13 '14 at 18:29
source share

Go to the folder located in php.exe.

C:\wamp\bin\php\php5.5.12\

open cmd and run the command below.

 php -r "readfile('https://getcomposer.org/installer');" | php 

composer.phar will be loaded into the same folder.

Create a folder called composer in the C:// driver (or anywhere, for the upcoming steps, remember the path).

move the composer.phar file to the C://composer folder.

Create the composer.bat file in the same folder with the contents below

 @ECHO OFF php "%~dp0composer.phar" %* 

create a file called composer without any extensions.

type NUL > composer command in CMD will help to do this quickly,

Open this file and place it inside the content.

 #!/bin/sh dir=$(d=$(dirname "$0"); cd "$d" && pwd) # see if we are running in cygwin by checking for cygpath program if command -v 'cygpath' >/dev/null 2>&1; then # cygwin paths start with /cygdrive/ which will break windows PHP, # so we need to translate the dir path to windows format. However # we could be using cygwin PHP which does not require this, so we # test if the path to PHP starts with /cygdrive/ rather than /usr/bin. if [[ $(which php) == /cygdrive/* ]]; then dir=$(cygpath -m $dir); fi fi dir=$(echo $dir | sed 's/ /\ /g') php "${dir}/composer.phar" $* 

Save.

Now set path , so we can access the composer from cmd.

  • Show desktop.

  • Right-click the My Computer shortcut on the desktop.

  • Click "Properties."

  • You should see the control panel section - Control Panel \ System and Security \ System.

  • Click "Advanced System Settings" on the left menu.

  • Click "Environment Variables" at the bottom of the window.

  • Select PATH from the list of user variables.

  • Add your PHP path (C: \ composer) to the PATH variable, separated from the existing colon string.

  • Click OK

Reboot the computer.

Or restart explorer only using the command below in CMD.

 taskkill /f /IM explorer.exe start explorer.exe exit 

Original article with screenshots here: http://aslamise.blogspot.com/2015/07/installing-composer-manually-in-windows-7-using-cmd.html

+11
Jul 25 '15 at 9:41
source share

This might be useful to someone:

On Windows 7, if you installed Composer using curl, you can find it in the same way:

C:\Users\<username>\AppData\Roaming\Composer

+10
Dec 29 '15 at 16:17
source share

Well, now this question is a bit outdated, as there is now an official installer that will "install the latest version of Composer and configure your PATH so that you can simply call the composer from any directory on your command line."

You can get it at: http://getcomposer.org/doc/00-intro.md#installation-windows

+5
Mar 02 '13 at 16:58
source share

A little more general if you put the package in the same folder as composer.phar:

 @ECHO OFF SET SUBDIR=%~dp0 php %SUBDIR%/composer.phar %* 

I would write this as a comment, but the code there didn’t help

+3
04 Sep '12 at 10:01
source share

Start> Computer: Properties> Change settings> Advanced> Environment variables> PATH: Change [add this line (without "") to the end of the line ";C:\<path to php folder>\php5.5.3" ] .. open cmd and type of composer thats it :-)

+2
Sep 18 '13 at 19:45
source share

I am using Composer-Setup.exe and it works great. Just in case, you need to know where the .phar composer is located (for use with PhpStorm):

 C:\ProgramData\ComposerSetup\bin\composer.phar 
+2
Mar 10 '17 at 10:14
source share

Sorry to figure it out, I just want to share my idea, an easy way for me is to rename composer.phar to composer.bat and put it in my PATH.

+1
Jan 10 '13 at 15:54
source share

An alternative (see Lusitanian answer ) is to register .phar files as executable on your system, an example phar.reg file:

 Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\.phar] @="phar_auto_file" [HKEY_CLASSES_ROOT\phar_auto_file\shell\open\command] @="\"c:\\PROGRA~1\\php\\php.exe\" \"%1\" %*" 

Just replace the path to php.exe with your PHP executable. Then you can also extend the %PATHEXT% command line variable with .phar , which allows you to enter composer instead of composer.phar while composer.phar is inside %Path% .

+1
Jan 24 '13 at 14:30
source share



All Articles