Installing Composer on OS X
Composer is a cross-platform dependency manager for PHP libraries. This article will explain how to install it on OS X and add an alias so you can use it from anywhere.
The first step is to download Composer, which will effectively create a Phar (PHP Archive) file called
composer.phar. From your terminal, run the following command:
curl -sS https://getcomposer.org/installer | php
In some cases, you might receive the following error:
Some settings on your machine make Composer unable to work properly. Make sure that you fix the issues listed below and run this script again: The detect_unicode setting must be disabled. Add the following to the end of your `php.ini`: detect_unicode = Off A php.ini file does not exist. You will have to create one. If you can not modify the ini file, you can also run `php -d option=value` to modify ini values on the fly. You can use -d multiple times.
For OS X 10.8, the
php.ini file should be located in
/private/etc/. If you don’t have one already, you can copy the default one:
sudo cp /private/etc/php.ini.default php.ini
Then, edit the file and append the following to it:
detect_unicode = Off
Save the file and rerun the
curl command above.
The resulting file will be called
composer.phar, a PHP Archive that can be executed directly via PHP. However, in my case, I want Composer to be accessible globally by simply typing
composer. To do this, move it to
/usr/bin/ and create an alias:
sudo mv composer.phar /usr/local/bin/ vim ~/.bash_profile
Add this to your
.bash_profile. It may be empty or non-existent, so go ahead and create it:
alias composer="php /usr/local/bin/composer.phar"
Now, relaunch your terminal and you’ll be able to access Composer simply by calling