How to install composer on Mac OS.
What is Composer?
PHP Composer is a cross-platform dependency manager that allows you to manage package dependency in your project.
In my previous article, I have explained PHP Composer – how to manage package dependency in PHP through composer.
How to Install Composer on Mac OS
To install composer in your Mac os, execute the following commands.
1 2 3 4 5 6 7 8 |
//Composer installation steps curl -sS https://getcomposer.org/installer | php All settings correct for using Composer Downloading... Composer successfully installed to: /Users/username/composer.phar |
The installer provided by composer check few PHP settings. If everything seems ok then it will download composer.phar in your working directory.PHAR stands for PHP archive, it’s an archive format for PHP which can be run on the command line, amongst other things.
NOTE: PHP Composer Installation Error
In some cases, you might get following error. To resolve this error open your php.ini file and enter this line (detect_unicode = Off) at the end of file.
1 2 3 4 5 6 |
The detect_unicode setting must be disabled. Add the following to the end of your `php.ini`: detect_unicode = Off The php.ini used by your command-line PHP is: /usr/local/etc/php/5.3/php.ini 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. |
We have successfully installed composer in our mac machine. To access composer globally, let’s move it to /usr/local/bin directory.
1 2 |
//Move composer to /usr/local/bin directory sudo mv composer.phar /usr/local/bin/ |
Now composer.phar is moved to /usr/local/bin directory. Let’s create an alias in .bash_profile file.
1 2 |
//Composer alias alias composer="php /usr/local/bin/composer.phar" |
If you are using Z shell then create this alias in .zshrc file. After that reload your bash_profile by using command source ~/.bash_profile.
Now everything is done to check whether composer is installed successfully or not type composer in your terminal. If it installed successfully then you get following output.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/ / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ / \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/ /_/ Composer version 1.0-dev (2d24ed8e74828645b999eeadb547927e16679edb) Usage: command [options] [arguments] Options: -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output -n, --no-interaction Do not ask any interactive question --profile Display timing and memory usage information -d, --working-dir=WORKING-DIR If specified, use the given directory as working directory. -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Available commands: about Short information about Composer archive Create an archive of this composer package browse Opens the package's repository URL or homepage in your browser. clear-cache Clears composer's internal package cache. clearcache Clears composer's internal package cache. config Set config options create-project Create new project from a package into given directory. depends Shows which packages depend on the given package diagnose Diagnoses the system to identify common errors. dump-autoload Dumps the autoloader dumpautoload Dumps the autoloader global Allows running commands in the global composer dir ($COMPOSER_HOME). help Displays help for a command home Opens the package's repository URL or homepage in your browser. info Show information about packages init Creates a basic composer.json file in current directory. install Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json. licenses Show information about licenses of dependencies list Lists commands remove Removes a package from the require or require-dev require Adds required packages to your composer.json and installs them run-script Run the scripts defined in composer.json. search Search for packages self-update Updates composer.phar to the latest version. selfupdate Updates composer.phar to the latest version. show Show information about packages status Show a list of locally modified packages suggests Show package suggestions update Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file. validate Validates a composer.json and composer.lock |