Composer

Overview

Composer is an application-level package manager for the PHP programming language that provides a standard format for managing dependencies of PHP software and required libraries.


Installation

Download the latest composer.phar file from the download page (scroll to the bottom). Check where the file downloaded to (most likely the downloads folder) and then move to user/local/bin

sudo mv composer.phar /usr/local/bin/composer

If you still have problems, such as "No file or directory", then create the bin directory if it doesn't exist and try again.

mkdir -p /usr/local/bin

If composer still can't be installed, then open the bin folder manually with

open /usr/local/bin

and drag composer.phar in there, and remove the .phar extension.


Once it's installed, run composer in the terminal, and you should receive the composer screen. In case of an error, make sure you follow the steps correctly with admin privileges (e.g. using sudo on a Unix machine).


Important composer commands

composer require package/library

  • Will update composer.json with the new dependency or create a new composer.json and composer.lock if they don't exist

composer install

  • Installs the vendor packages according to composer.lock (or creates composer.lock file if not present)

composer update

  • Will regenerate composer.lock with the new composer.json dependencies and versions, no matter if composer.lock exists or not

composer dump-autoload -o

  • Regenerates the list of all classes that need to be included in the project (vendor/composer/autoload_classmap.php).

Comments (0)

Search Here