This article covers how to install Composer on your Linux system and use it for handling the packages and dependencies of the PHP programming language. Composer is a dependency manager for PHP (similar to npm for Node.js or pip for Python ).
With Composer, you can specify the PHP libraries your project depends on, and it will pull and manage all libraries and dependencies for you.
Composer is used in all modern PHP frameworks and platforms such as Laravel, Symfony, Drupal, and Magento.
To install PHP Composer on Ubuntu:
1. Ensure that you have all the necessary requirements installed on your system:
$ sudo apt update
$ sudo apt install wget php-cli php-zip unzip
2. Composer offers an installer written in PHP that we’ll use to install Composer. Use wget to download the installer:
$ wget -O composer-setup.php https://getcomposer.org/installer
The command above will save the file as composer-setup.php in the current working directory .
3. Run the following command to install Composer in the /usr/local/bin directory:
$ sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
4. To install composer locally enter:
$ sudo php composer-setup.php --install-dir=/path/to/project
5. When a new Composer version is available, you can update your installation using the following command:
$ sudo composer self-update