How to install Composer in Windows

I wanted to install PHP Composer in Windows. And to begin, I already have a copy of XAMPP 1.8.1, I think if you have a different way to get your PHP that should not matter. I tested this to work for Windows 7 but it should work for all versions of Windows.

0. Download and install XAMPP

You can download XAMPP here. I got the 7zip version rather than the installer itself. The ZIP version is similar, just with a larger file size. I extract the xampp folder into my C: drive, i.e. to C:xampp. Then install it by opening the file C:xamppsetup_xampp.bat. That will set the paths in XAMPP’s configurations.

1. Setting up environment variables

Firstly, we would need to let the command prompt know where to find php.exe. In my computer set up, it is located in ‘C:xamppphp’. Yours might be in ‘C:xampp-litephp’ depending on where you install your XAMPP.

We need to edit some system environment variables:

editing system environment variables

Click on ‘Edit the system environment variables’, a dialog box will pop up. Click on ‘Environment Variables…’, you should be greeted with the following dialog box:

editing the path for environment variables

My path looks like this before I add anything under the system variable’s Path section, yours will be different:

[code language=”bash”]C:Program FilesCommon FilesMicrosoft SharedWindows Live;C:Program Files (x86)Common FilesMicrosoft SharedWindows Live;C:Program Files (x86)NVIDIA CorporationPhysXCommon;%SystemRoot%system32;%SystemRoot%;%SystemRoot%System32Wbem;%SYSTEMROOT%System32WindowsPowerShellv1.0;C:Program Files (x86)Windows LiveShared;C:Program Files (x86)SproutCorebin;N:vagrantvagrantbin;C:Program Files (x86)QuickTimeQTSystem[/code]

Append your XAMPP PHP directory at the back of what is already there:

[code language=”bash”];C:xamppphp[/code]

Open a new command prompt (don’t use existing one), and type “php -v” and see if there are any problems. You should see the following:

[code language=”bash”]C:UsersKahWee>php -v
PHP 5.4.7 (cli) (built: Sep 12 2012 23:48:31)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies[/code]

PHP in command line Windows

2. Avoiding MSVCR71.dll error

I encountered an error: “php.exe – System Error: The program can’t start because MSVCR71.dll is missing from your computer. Try reinstalling the program to fix this problem.”.

PHP MSVCR71 dll error
PHP MSVCR71 dll error

This error is caused by the “php_pgsql.dll” extension. We can proceed by disabling PostgreSQL if we don’t use it. If you do need it, you may consider installing Microsoft .NET Framework 1.1.

Open the file ‘php.ini’ in ‘C:xamppphp’ and search for “pgsql”. Disable the extension by placing a semicolon in the beginning of the line this way:

[code language=”bash”];extension=php_pgsql.dll[/code]

3. Enable the openssl extension

Go to C:xamppphpphp.ini and search for “extension=php_openssl.dll”:

[code language=”bash”];extension=php_openssl.dll[/code]

Make sure it is uncommented to:

[code language=”bash”]extension=php_openssl.dll[/code]

4. Command Prompt action

Now we will navigate to the folder through the command prompt. Use:

[code language=”bash”]cd /D C:xamppphp[/code]

The above command changes the directory to C:xamppphp where I will install my composer file. Conveniently, it is also within the path of system variables so I can run composer.phar anywhere. The /D allows you to change to a different drive. If that’s not needed, you can run simply “cd C:xamppphp”.

Then you can run the following code:

[code language=”bash”]php -r "eval(‘?>’.file_get_contents(‘’));"[/code]

You should see this response after waiting for less than a minute:

[code language=”bash”]C:xamppphp>php -r "eval(‘?>’.file_get_contents(‘’));"
#!/usr/bin/env php
All settings correct for using Composer

Composer successfully installed to: C:xamppphpcomposer.phar
Use it: php composer.phar[/code]

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

[code language=”bash”]@ECHO OFF
php %SUBDIR%composer.phar %*[/code]

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

5. And you’re done

Okay you work on composer, just use:

[code language=”bash”]composer[/code]

Have fun!

Leave a Reply

Your email address will not be published. Required fields are marked *