cd-ing into a directory then running ./command, or worse yet, php command.php, sucks!
As an example, I wanted to run the doctrine command from anywhere.
I already have composer installed globally, and no longer have to type php composer.phar, but I haven’t blogged it since it was pretty easy, but anyway here it is:
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
Then you can just type composer from anywhere. If you already have composer you should run sudo composer self-update. Anyway on to our php binaries (Doctrine, PHPUnit, Behat, you name it). If it’s a fresh install of composer you should see when you type composer global install:
Composer could not find a composer.json file in /home/username/.composer
Now we know where we can create our composer.json. Go to the sites for the packages you would like and copy paste the require field info; Here is Doctrine’s:
Now run composer global install and it will install in /home/username/.composer/vendor. The bin folder is inside that. Lastly we need to have our bin path set in our PATH environment variable, so the system knows to check that folder for a binary matching the command’s name. edit ~/.bashrc (it could be .bash_profile or something similar). At the end, paste this in:
now exit the shell and open a new terminal up and log back in. you can now type doctrine into the command line and lo and behold, your composer executables are rocking!