What is Composer and how to use it? - BRS MEDIA TECHNOLOGIES
composer for php

What is Composer and how to use it?

Composer was inspired by projects like NPM and Bundler. Dependencies save you time and energy. Functionalities you may need for your app like sending e-mails or login can all be easily included as third party libraries.

Composer is a exceptional dependency manager for PHP. The vast selection of compatible packages are hosted on the official Composer repository called Packagist. These packages are opensource so you can contribute to them too. Popular frameworks and tools lik Laravel, PHPUnit and Mongolog can all be found there.

Prerequisites:

The software you need is as follows:

Composer can be installed in two different ways

  1. install Locally
  2. Install Globally (Recommended)

Link to download manually https://getcomposer.org

Some version of PHP5, preferably the latest. Composer is compatible with versions 5.3.2 and up.

Command to install Composer in Ubuntu

>$ sudo apt update
>$ sudo apt install composer
>$ composer --version

Commands :

init command create you composer.json schema with some arguments

>$ composer init

Install command first create a composer.lock if not exists composer.lock file. composer lock file contains composer.json all package with version.

>$ composer install

Composer required : require is the most used command, it installs the package into you package

>$ composer require

install specific package

>$ composer require vendor-name/package-name

It updates all outdated packages

>$ composer update

Composer updates specific packages

>$ composer update vendor-name/package-name

Show command return all package name from you project

>$ composer show

Remove command remove php package from you project

>$ composer remove package-name

You can see all outdated packages, which package hasn’t the latest version

>$ composer outdated

Dump-autoload : autoload is the most important command. This command adds class, alias, provider etc inside vendor’s composer folder. This file (no class) returns an array of all aliases and file based on the autoload section composer.json. It just regenerates the list of all classes that need to be included in the project

PATH vendor/composer/autoload_classmap.php

>$ composer dump-autoload



Key Terms:

  • composer
  • ,
  • Open Source Software
  • ,
  • php composer

Related Article

UFW firewal

UFW Firewall on Ubuntu

How to Install UFW Firewall on Ubuntu with GUI? The objective is to show you how to enable and disable […]

Linux File & Folder

Linux File/Folder Permissions

sudo chmod -R 777 [Path:/media/folder/files] Explained Command: SuperUserDo ChangeMode -Recursively OwnerGroupUser [Path of File or Directory or Drive] Every file […]

dpkg command in linux

DPKG as Package Manger in Debian based Linux distributions

Debian Linux and other Debian based Linux distributions, such as Ubuntu and Linux Mint, use dpkg as a package manager. […]