Category Archives: Laravel

Installing Composer on OSX

You’ve been reading a heap of articles on Laravel and the movement towards using a package manager for PHP… Composer be thy name.

Composer allows us to install a host of packages (managed by Packagist) by building a simple JSON file in the root our project. By running a simple command

$ composer install

we’re able to get the package, along with any dependencies it might have.

Let’s walk through a basic tutorial on how to get Composer installed globally on our development machine. The machine being used in this instance is a MacBook Pro running OSX Mountain Lion and MAMP.

Step 1 – Getting the Composer PHP archive (composer.phar)

Curl should be installed by default on your PHP/Apache development environment. If not, I suggest you do some Googling to find out how get it running (generally simply ensuring a DLL file is present and uncommenting a line in your php.ini file, then restarting your web server).

To get the archive, simply jump into your favourite terminal and type the following

$ cd ~/Downloads
$ curl -s | php -d detect_unicode=Off

This will get the archive and download it to the directory you’re currently in.

Step 2 – Move the file somewhere into your path

You’ve got the file… and assuming you can run php from the command line (if not, see here), you should be able to run

$ php composer.phar --version

at the command line and have some output similar to

Composer version 6a1262e675b5c1c2c7b1cc58a14028f67885b880

This is all well and good… but

$ php composer.phar --version

is just plain ugly.  Let’s pretty it up.

Our ideal situation is to move the composer.phar file into our path… somewhere.  So which to choose?  Personally, I’ve used /usr/local/bin/  as my destination, but you could just as easily use /usr/bin (I find /usr/local/bin is far less cluttered, though).

Let’s move it (and rename it so it’s prettier at the same time)

$ cd ~/Downloads
$ sudo mv composer.phar /usr/bin/composer

And that’s it. Now, no matter what folder you’re in on your system, you should be able to run

$ composer --version

and it will work.

You’re welcome.