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

How to Disable Snap on Ubuntu 22.04

How to Disable Snap on Ubuntu 22.04

Contents0.1 Introduction0.2 Requirements0.3 Step 1: Disable Snap0.4 Step 2: Remove Snap packages0.5 Step 3: Remove Snap1 Next Steps1.1 Key Terms: […]

remote desktop ubuntu from windows

Remote Desktop Access Linux from Windows

Ubuntu 20.04 Remote Desktop Access from Windows 10 step by step instructionsFirst step is to install Remote Desktop Protocol (RDP) […]

Git Command

Git Repository Commands

Contents1 Basic GIT Commands2 Intermediate GIT Commands3 Advanced Commands4 How to do git checkout? Basic GIT Commands git config –global […]