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.

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

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\’.

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:

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.

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

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?

  • BigJonMX

    “First you need Xampp installed…” WRONG!
    “Disable pgsql…” NOT NEEDED.
    This is all very misleading.

    • Rana Naeem

      I don’t think so, This all is misleading!
      In most of cases you will get error:

      “The program can’t start because MSVCR71.dll is missing from your computer. ”

      this error is due to pgsql extension is enabled, you need to disable it before proceed or you must have .NET framework installed.
      Why you should use composer, if you didn’t installed Xampp or Wamp.

      • Rockson Agyeman

        @Rana Naeem do not worry your head over “I don’t think so, This all is misleading!”. He contributed nothing but just came to criticize. Thanks for your help with the tutorial.

  • Diana Avila


    I hope you are able to help, I created the composer.bat file under the php directory with the following content:

    SET SUBDIR=%~dp0
    php %SUBDIR%composer.phar %*

    but when trying to use composer in the command line I get an error saying: ‘composer’ is not recognized as an internal or external command….

    I checked the name of the file for typos but, seems to be okay

    Thanks in advance!

    • Diana Avila

      Never mind, I solved it. I’ll post what I did in case someone else need help.

      I created a new text file and somehow, even after being saved with the .bat extension, it wasn’t changing the file type.

      So I created a new tab on sublime text (or your text editor of choice) and save it as composer.bat right since the beginning and it worked.


  • Asif

    thanks for tutorial it worked for me

  • Mayeenul Islam

    @NaeemRana wonderfully explained. It worked for me too. I’m a WAMP user, installed composer using offline version.
    – I used the first step so my CMD got the PHP commands
    – Then using the offline version of composer.phar I then followed this SO thread ( and installed Composer.
    Kudos to your effort.

  • Buck Powell

    as soon as I run php composer.phar self-update I get a message stating “Could not open input file composer.phar”

  • Buck Powell

    I don’t have the composer.phar file. Fresh install

  • arnob

    when i run this line (D:xampphtdocszend> php composer.phar self-update) is show “Access is denied”. Now what can i do.?

    • Shûññö Vûböñ

      same problem .. Do you solve your problem ?

  • jonathan ansell

    not a bad article – i found it useful. you should add a reference to xampp in the title, so that google searches show up better.
    you didn’t explain what the bat file does – (i don’t speak .bat, i’m usually on unix)

    • Rana Naeem


      .bat file is specifically a windows scripting file, i don’t think i can be directly run on UNIX. Wine( could be used to run Window files on Linux. alternately files with .sh extension are Linux scripting files.

      Above is not solution to your problem. installation in Linux is far easy than windows.

      run following commands in terminal.

      $ curl -s | php
      $ sudo mv composer.phar /usr/local/bin/

      and create alies ‘composer’
      $ alias composer=’/usr/local/bin/composer.phar’

      This way you can invoke composer with just composer
      $ composer create-project –prefer-dist –stability=dev yiisoft/yii22-app-basic yii2-basic

      • jonathan ansell

        hi – thanks for the reply, i think you mis-understood me.
        i’m using windows for this task, but i come from a unix background… so i’d be grateful for a line by line explantaion of what the bat file does :-)

        • Rana Naeem

          ahh ok. Glad it helps!

  • PetoB

    OK old, but useful :) thanks

  • sombir

    I am facing the some problem please help.

    i am getting below error :

    Connection error [ERR_CONNECTION]:Unable to connect to

    Request to failed with errors:

    Failed to open stream: A connection attempt failed because the connected party

    did not properly respond after a period of time, or established connection failed

    because connection host has failed to respond.

    extension php_openssl and ‘php_curl` already enabled in php.ini file lacated in C:wampbinphpphp5.5.12.

    When i run the ping command ping it is giving me below error :

    Pinging with 32 bytes of data

    Reply from Destination host unreachable

    Reply from Destination host unreachable

    Reply from Destination host unreachable

    Reply from Destination host unreachable

    Please help to solve this issue.

    • Rana Naeem

      I just downloaded the installer file from same host. You can download file manually.

      • Rana Naeem

        Also it is not

  • ifao

    Hi ! Thanks for the article !
    I’m still facing the same problem and I can’t find any help on the net : it’s the same error as sombir. I checked the php.ini file, I removed my firewall during the try, but nothing helped… If you have any idea how to solve this, it will be helpful ! =)

  • Krish Nakum R


  • Fahad Ubaid

    I am facing the problem of ambiguous class resolution…. and due to that problem I cannt install other packages like lavacharts and tcpdf…….. please help me.. i am new to understand laravel framework….

  • kaleem

    i got Parse error> syntax error, unexpexted ‘?’ in command line code (1) when try to install

  • James O’Donnell

    I got unexpected ‘?’ in the command line code when I tried to install

  • Robert

    php -r “eval(‘?>’.file_get_contents(‘’))”;

    makes this output

    Parse error: syntax error, unexpected ‘?’ in Command line code(1) : eval()’d code on line 1

    this in an xampp windows

  • Vipin Chauhan

    php -r “eval(‘?>’.file_get_contents(‘…”;

    Output Parse error: syntax error, unexpected ‘?’ in Command line code(1) : eval()’d code on line 1

    this in an Wamp windows

  • SamJet

    “Edit path variable and set it to D:xamppphp. 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.”

    Suggesting a few changes to make this process less disastrous for new users.

    Clearly mention the path variable that is UNDER System Variables. Path variable may also be found under User Variables.

    Mention the fact about putting the new info at the end of line earlier and do mention the use of semicolon to separate the data from existing one.

  • Imran Ahmed