Anthony
Anthony

Reputation: 4050

Installing Composer in WAMP PHP Google+ Project, PHP is not recognised

I am following this PHP Google+ tutorial and I am trying to install composer in my WAMP directory

C:\wamp\www\gplus-quickstart-php>curl -s https://getcomposer.org/installer | php

but I'm getting this error

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

How do I resolve this problem? I already have PHP installed (via WAMP Server). Do I have to install PHP in my computer as well?

Upvotes: 4

Views: 25833

Answers (6)

RiggsFolly
RiggsFolly

Reputation: 94682

Ok a couple of things you need to do here.

First windows does not have a curl processor like unix so you need to use the other option for installing Composer

php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"

For this to work you need the php.exe processor to be on your path, so you have 2 options here. Either add the c:\wamp\bin\php\phpx.y.z folder to your PATH thats the bad option for WAMPServer as you can have more than one version of PHP installed and when you activate another version your PATH will still be pointing at the Old version. Or my prefered option write yourself a little .cmd file which will do it for you like this

filename = addphp.cmd

PATH=%PATH%;c:\wamp\bin\php\phpx.y.z

Put this file in a folder already registered on your path so you can run it from anywhere in a command window.

Now you will have to edit the \wamp\bin\php\phpx.y.z\php.ini file. This is similiar to the one used by php code run through the Apache web server but is only used by the PHP CLI (Command Line Interpreter)

Make sure the extension php_curl is uncommented or the above line wont work i.e. remove the ; comment symbol

extension=php_curl.dll

So now run a command window, cd into the folder that you want composer installed into and run the command above, then follow the rest of the install instructions on Install instructions

Upvotes: 16

Nick Weavers
Nick Weavers

Reputation: 564

First, to get php into your path see my answer here

Installing composer is explained nicely here (code below just for illustration. Be sure to get latest from the link)

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

A quick check to confirm it worked:

    $ php composer.phar --version
    Composer version 1.2.1 2016-09-12 11:27:19

Upvotes: 0

jim smith
jim smith

Reputation: 2454

If using phpstorm you can download composer using their built in composer option in the tools menu.

You can run it from CLI by locating your php.exe, e.g

C:\wamp\bin\php\php7\php.exe composer.phar install

Upvotes: 1

Farid Ait Benali
Farid Ait Benali

Reputation: 21

first you have to add your php path to system after go to php.ini and rmove ; for extension=php_openssl.dll it will be active 3 run this command in cmd :

php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"

Upvotes: 1

gagath
gagath

Reputation: 123

On windows, just installed composer with windows installer -> easy and with wizard - like it.

https://getcomposer.org/Composer-Setup.exe

Upvotes: 11

programmingnewb
programmingnewb

Reputation: 129

No idea if anyone will answer this late but I'm having issues with this. I created the .cmd file and put in the path as suggested. I put this file in my wamp\www\sitename folder. Is that not what you mean when you say putting it in a "registered path folder"? After creating the file, and running the code it still says php not recognized.

Upvotes: 0

Related Questions