1

I'm not sure that this is a Path alias, but I'm not sure how to do this in Windows 7.

When I run PHP composer, it shows all composer options, as expected.
However if I try to run in like

C:\>php composer.phar composer global update squizlabs/php_codesniffer:2.9.1

it returns

[Symfony\Component\Console\Exception\CommandNotFoundException]
Command "composer" is not defined.

EDIT: I had to install this behind a proxy, and I couldn't use a installer.

How can I create a working alias for simply running

c:\somewhere\anywhere\ composer

instead of php composer.phar so that I can call composer from anywhere on the filesystem and not only inside the php directory?

staminna
  • 468
  • 1
  • 5
  • 26
  • 2
    `php composer.phar` replaces `composer`, you don't need both. – Devon Bessemer Apr 16 '18 at 15:12
  • Why do you run `php composer.phar composer global (...)` with two calls to composer? – Nico Haase Apr 16 '18 at 15:41
  • You got a point @Devon but The point is that I can only call this in side the directory of php – staminna Apr 17 '18 at 09:53
  • @NicoHaase You are right. The point is I can't simply call "composer" from anywhere besides where php is installed. I need a alias and must insert into the path – staminna Apr 20 '18 at 14:56
  • No, you don't. What happens if you run `php composer.phar global update squizlabs/php_codesniffer:2.9.1`? – Nico Haase Apr 20 '18 at 16:16
  • @NicoHaase it works, but not if I run "composer" anywhere else besides in the php install directory – staminna Apr 26 '18 at 10:03
  • Then you should specify the path to your `composer.phar` – Nico Haase Apr 26 '18 at 10:16
  • @NicoHaase I am happy to accept your answer if you could explain how to achieve that – staminna Apr 26 '18 at 13:46
  • Some seconds of googling pointed me to http://webdevzoom.com/how-to-install-composer-on-windows/ - maybe, you should try using google too? ;) – Nico Haase Apr 26 '18 at 13:57
  • The first bullet in your google search makes use of a installer. I can't use installers at work. Also I am behind a proxy which made the install more more difficult, but it works in the directory where composer.phar is installed only. p.s. I googled – staminna Apr 27 '18 at 14:36

1 Answers1

1

Here's what I did for Windows PowerShell. I know you asked for help to add this to your PATH, but sadly this was the best that I was able to come up with.

  1. Open up your profile (found at $PROFILE, but you might want to edit something a bit more personal like $PROFILE.CurrentUserCurrentHost or $PROFILE.CurrentUserAllHosts. I ended up using the latter as I want to be able to use this in PowerShell ISE and the regular command line.
  2. Add the following: function composer { php $HOME\composer.phar $ARGS }
  3. Save the file and restart PowerShell.

That should do the trick, I can now do the following:

PS C:\Users\NathanWindisch> composer
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 1.8.5 2019-04-09 17:46:47

Usage:
  command [options] [arguments]
...