Installing Composer to PHP on Windows

There are a few small issues and changes, when installing and using Composer dependency manager to PHP running on localhost (local development environment) on Windows.

This article should clarify these things and answer some questions about using Composer on Windows.

Enabling HTTPS

First of all, you need to have support for HTTPS protocol and wrapper enabled in your PHP. Edit php.ini and look for extension=php_openssl.dll line. If if has ; character in the beginning (library disabled), remove it (enable library). Then restart your Apache.

Now, to install Composer.

Just a single installation

If you need it for just a single project (it’s author forces you to use it, but you normally don’t care for all these composer.json files), then you may use typical way, described at Download page. I.e. execute:

curl -sS https://getcomposer.org/installer | php

from command-line. If this does not work (or if you don’t have curl), try alternate version of:

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

It this, again, don’t work, try the next method of central installation.

Central installation

In most case you’d like to use Composer for many projects. Therefore you need to install central version, that will be accessible in every path. The simplest (and the only tested by me! :>) method is to use installer file. You’ll get it at Download page or in here.

Run downloaded Composer-Setup.exe file and follow on-screen instructions.

Default settings seems fine, so clicking Next > few time should do the trick.

Once Composer is installed on your system, you should either exit all terminal windows and/or all Windows Explorer windows and open them again, to force system to re-read PATH environment variable, just updated by Composer installer. Alternatively, if above seems to be not working, restart entire Windows.

Usage

Most pages for developers and most code repositories are handled by geeks using Linux. So, they write to run php composer.phar install. This won’t work under Windows and should be replaced by simple composer install. Since Composer is (should be) listed on your PATH, it should be available in any directory.

That, of course, matches only installing “central” installation, using Composer-Setup.exe file. If you installed only single, per-project version of Composer, you’re normally running php composer.phar install.

Leave a Reply