Composer is a package manager for installing and managing the required modules for PHP applications. PHP composer dependency manager is similar to pip for python or npm for Node.js applications.
Using the composer tool, you can manage all PHP dependencies and libraries for your project. The required PHP modules can be installed easily in your application with the help of the composer manager.
This tool is used in almost all modern PHP frameworks such as Drupal, Laravel, and Magento.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Composer queries on Ubuntu.
In this context, we shall look into how to install PHP Composer on your Linux Ubuntu 20.04 environment.
Before performing this Installation procedure, ensure that the following requirements are met:
To Install PHP composer on your Ubuntu 20.04 system, simply follow the steps given below.
1. Install PHP modules
First, make sure that all composer necessary PHP requirements are installed on your system. Access the command line application 'Terminal' by using the 'Ctrl Alt+t'.
Now, If PHP is not installed then, just update the apt repository and run the below-mentioned command to install PHP requirements:
$ sudo apt update
$ sudo apt install wget php-cli php-zip unzip
2. Download the Composer setup
Now, download an executable file to install the PHP composer on your system. The following wget command will help you to download the setup file:
$ wget -O composer-setup.php https://getcomposer.org/installer
When the above command is executed, it saves the installer file 'composer-setup.php' in the current working directory of your Ubuntu system.
3. Install PHP composer
Php composer can be installed either globally or locally as a part of the project. Here, we have installed the PHP composer globally in this guide. To install the PHP composer globally. You need to place the downloaded setup file in the system path '/usr/local/bin' directory. So, using the following command you can install PHP composer globally on your Ubuntu 20.04 system:
$ sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
Once the composer installation is completed on your system. Now, run the composer in the terminal to use the composer environment.
$ composer -v
The above command will show you the installed PHP composer version and all options that will help you to use the composer through the terminal.
Using the composer, you can create a root directory for php project by running the following command:
$ mkdir ~/test-composer-project
$ cd ~/test-composer-project
Now, if you want to install a PHP module in the above directory then, use the following syntax to install a new PHP module:
$ composer require {php-module-name}
You can also update the composer to a newly available version by running the following command:
$ sudo composer self-update
This article covers how to install PHP Composer on Ubuntu 20.04 system. Composer is a popular dependency management tool for PHP, created mainly to facilitate installation and updates for project dependencies. It will check which other packages a specific project depends on and install them for you, using the appropriate versions according to the project requirements. Composer is also commonly used to bootstrap new projects based on popular PHP frameworks, such as Symfony and Laravel.
To Install PHP Composer on Ubuntu:
1. Update your packages:
$ sudo apt-get update
2. Install the curl utility:
$ sudo apt-get install curl
3. Download the installer:
$ sudo curl -s https://getcomposer.org/installer | php
4. Move the composer.phar file:
$ sudo mv composer.phar /usr/local/bin/composer
5. Use the composer command to test the installation. If Composer is installed correctly, the server will respond with a long list of help information and commands:
# composer