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:\xampp\setup_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:\xampp\php\’. Yours might be in ‘C:\xampp-lite\php\’ depending on where you install your XAMPP.
We need to edit some 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:
My path looks like this before I add anything under the system variable’s Path section, yours will be different:
C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\SproutCore\bin;N:\vagrant\vagrant\bin;C:\Program Files (x86)\QuickTime\QTSystem\
Append your XAMPP PHP directory at the back of what is already there:
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:
C:\Users\KahWee>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
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.”.
Open the file ‘php.ini’ in ‘C:\xampp\php\’ and search for “pgsql”. Disable the extension by placing a semicolon in the beginning of the line this way:
3. Enable the openssl extension
Go to C:\xampp\php\php.ini and search for “extension=php_openssl.dll”:
Make sure it is uncommented to:
4. Command Prompt action
Now we will navigate to the folder through the command prompt. Use:
cd /D C:\xampp\php
The above command changes the directory to C:\xampp\php 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:\xampp\php”.
Then you can run the following code:
php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"
You should see this response after waiting for less than a minute:
C:\xampp\php>php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));" #!/usr/bin/env php All settings correct for using Composer Downloading... Composer successfully installed to: C:\xampp\php\composer.phar Use it: php composer.phar
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.
5. And you’re done
Okay you work on composer, just use: