How to install Composer (Dependency Manager for PHP) in Windows

Installation of Composer on Windows(XP, 7, 8) is easy, its only take few steps.

What is Composer? it is a dependency manager tracking local dependencies of your projects and libraries. get it here. It allows you to declare the dependent libraries your project needs and it will install them in your project for you.

I assume you have xampp installed, you can get latest version from here.

Step 1) First step is to make you enable run PHP commands on Command prompt. so let the CMD(Command prompt) know where is your php.exe exist. In my case I have xampp installed in D:/ drive. so it is D:\xampp\php. copy this path.

Next right click on My Computer, then click on Advanced System Settings, under Advance tab you will see Environment variables button. click on that a dialog box will pop up like bellow.

composer installation

 

Edit path variable and set it to D:\xampp\php. make sure you put this at the end of path string. its actually already have few paths, which are necessary to run other commands in windows.

Now check it works? open new command prompt window and run “php -v” command, if everything goes fine it should return something like bellow.

composer installation CMD

Step 2) Open your php.ini file by locating directory ”˜D:\xampp\php\ and search for “pgsql” and Disable the extension by placing a semicolon in the beginning of the line.

extension=php_pgsql.dll

also enable SSL extension by un-commenting this line. this will help in download composer setup files.

extension=php_openssl.dll

Step 3)  Finally now by running following command you can download composer to your environment. locate to folder where you want to install composer. like ”˜D:\xampp\php\.

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

This will download and install Composer within less than a minute.

Now you can create a composer.bat file, C:\xampp\php\composer.bat and include the following code:

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

This allows you to run the command “composer” anywhere using command prompt.

You can use composer with any project directory which is set to use composer by using Command prompt run following commands in that directory.

D:\xampp\htdocs\zend> php composer.phar self-update
D:\xampp\htdocs\zend> php composer.phar install

Let say you want to install Yii2 development version with basic application using composer.

D:\xamp\htdocs> composer create-project --prefer-dist --stability=dev yiisoft/yii
2-app-basic yii2-basic

It will download yii2 development version including its dependencies. see how faster it is.

installing yii2 using composer

Composer saves time and making your life easier, isn’t it?