Install global packages with Composer under Windows

Published:

Content

Introduction

It is possible to manage global packages with the PHP dependency manager Composer, similar in the way PEAR does. In this blog post I would like to show how-to install and configure Composer with a Microsoft Windows operating system (OS) and install some useful PHP tools globally with Composer.

Most of the tools are listed on the website The PHP Quality Assurance Toolchain.

Install Composer

Composer should be installed with the official Windows Installer. After that the composer command line application should be usable, since the installer modifies the system PATH.

Configure Composer

  1. Create an environment variable with the name COMPOSER_BIN_DIR and the value %APPDATA%\Composer\vendor\bin. By doing this the default installation directory for executable files is configured. The value above is the same as the default value. This step is required in order to execute the following step.
  2. Add the environment variable COMPOSER_BIN_DIR to the PATH environment variable in order to run the installed tools via the command line later.

If Composer is used in a development environment (e.g. a workspace computer) the PHP extension Xdebug may be used for debugging.

Running Composer with the Xdebug extension prints the following warning message to the standard output:

You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug

To get rid of the warning an environment variable with the name COMPOSER_DISABLE_XDEBUG_WARN and the value 1 can be created.

Install a package globally

Composer offers the global command to install and update packages globally. In order to install a package the composer global require <package> command can be used. The following batch script automates the global installation of some common PHP tools with Composer.

Update all global packages

Run the composer global update command.

Uninstall a global package

To uninstall a package with Composer, remove the line for the package from the require section of the file %APPDATA%\Composer\composer.json and run the composer global update command.

Update Composer

To update Composer itself the composer self-update command can be used.

The self-update command checks https://getcomposer.org for newer versions of composer and if found, installs the latest.

Conclusion

This blog post described the usage of the PHP dependency manager Composer and the handling of global packages under a Microsoft Windows OS.

For further information how-to use Composer under a *-nix OS refer to the following sources: