Skip to content

Manual installation

johnstevenson edited this page Feb 8, 2013 · 23 revisions

Contents

The Basics

The goal is to download Composer to a single directory and set things up so that it can be run from any location by typing: composer into a command window. This is what the Composer-Setup installer does automatically, but you can achieve the same in a few simple steps.

Command line PHP

Composer is a PHP script that is called from the command line, through the PHP CLI (Command Line Interpreter). You can run this by typing path\to\my\php.exe, followed by the name of the php script, but it is much easier to invoke it by typing php. This will only work if the PHP directory is in your path environment variable and you can check this by typing php -v. If the version is displayed you then you are done, otherwise you must add the directory containing php.exe to your path.

Download Composer

Decide where you want to install Composer to. If you wish to set it up for all users, please ensure that the directory you choose is writeable by everyone. Once you have created the directory, cd (change directory) to it in your command window and type:

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

which will download Composer into your directory. There are other ways of doing this. If you have curl installed you can type:

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

Or if you have git installed you can use the above command in Git Bash. Note that if you see any Message Box errors running Git Bash, click past these and check that Composer has downloaded - these errors can sometimes be caused by an extension being listed in your php.ini after other extensions that require it.

If the installation has failed, then read the errors that are displayed, correct them in your php.ini and try again. Otherwise type php composer.phar and you should see the Composer help displayed.

Create shim files

Your computer does not know how to run the composer.phar script, but it does know how to run a batch file from a Windows command console, or a shell script from Cygwin or Git Bash. Adding these shims is how the composer command get translated into running this file. We will create these now.

Batch file

Create a file called composer.bat in your directory and add the following to it:

@ECHO OFF
php "%~dp0%composer.phar%" %*

Shell script

Create a file called composer in your directory (note there is no file extension) and add the following to it, making sure that you save it with Unix line-endings.:

#!/bin/sh

# This file must be saved with Unix line endings, or Cygwin will choke

dir=$(d=$(dirname "$0"); cd "$d" && pwd)

if command -v 'cygpath' >/dev/null 2>&1; then
  dir=$(cygpath -m $dir);
fi

dir=$(echo $dir | sed 's/ /\ /g')
php "${dir}/composer.phar" $*

Finally you must add your directory to your path. Then open a new command window (so it pulls in your new settings) type composer and you should see the Composer help displayed. Full documentation can be found at http://getcomposer.org and a repository of packages can be browsed at Packagist.

Changing your Path

There are plenty of online tutorials about changing your Path environmental variable, so we will not cover it here. It is worth mentioning though that your changes will not propogate through to running programs, so you will have to open them again. Failing this it may be necessary to either log-off, switch user or restart your computer.