Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Global installation of PHP tools with Composer

Global installation of PHP tools with Composer

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:

$ composer global require phpunit/phpunit
$ composer global require phpunit/dbunit
$ composer global require phing/phing
$ composer global require phpdocumentor/phpdocumentor
$ composer global require sebastian/phpcpd
$ composer global require phploc/phploc
$ composer global require phpmd/phpmd
$ composer global require squizlabs/php_codesniffer

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:

export PATH=~/.composer/vendor/bin:$PATH

and phpunit is now available on your command line.

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

composer global update

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

@SoftwarePerfectionist

This comment has been minimized.

Copy link

SoftwarePerfectionist commented Oct 18, 2017

Thanks. I installed phpdocumentor in my tiny 1 class library and about shart myself when I saw all the things added. I hate to install these php tools locally to projects when I use them on all projects anyways. Adding all the tools to each project always makes the projects totally littered with too much bloat.

@gemmadlou

This comment has been minimized.

Copy link

gemmadlou commented Nov 7, 2017

Thanks

@kiproping

This comment has been minimized.

Copy link

kiproping commented Nov 7, 2017

In my case I don't have .vendor folder.

@jawira

This comment has been minimized.

Copy link

jawira commented Aug 29, 2018

I definitively would added composer global require hirak/prestissimo, it's not a tool but speeds up downloads a lot.
Also, my bin folder was already added to path... I suppose it's because I installed composer with apt-get install composer.

@jawira

This comment has been minimized.

Copy link

jawira commented Aug 29, 2018

localheinz/composer-normalize it's also a cool tool !
https://packagist.org/packages/localheinz/composer-normalize

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.