Global installation of PHP tools with Composer – Rob Allen's DevNotes


: 2

The Composer package manager along with the Packagist repository site is quickly becoming the defacto PHP package management system.

One feature I found out about recently is that you can install packages globally rather than locally into your project. I think that this is most useful for development tools, such as PHPUnit which are then available everywhere.

To install a composer package globally, you run the usual require command, but with the addition of the global modifier. So to install PHPUnit, you would run:

This will install PHPUnit and all its dependencies into the ~/.composer/vendor/ directory and, most importantly, the phpunit CLI tools are installed into ~/.composer/vendor/bin/.

Simply add this directory to your PATH in your ~/.bash_profile (or ~/.bashrc) like this:

and phpunit is now available on your command line.

To keep your tools up to date, you simply do this:

To remove a package, you edit ~/.composer/composer.json and then run composer global update.