What is Composer

Composer is an application level package manager for the PHP language that provides a standard format for managing dependencies of PHP software and libraries. In other words we can say that, “it is a tool for dependency management in PHP”, which deals with “packages” and “libraries”.

Composer runs on “command line” and allows you to declare the libraries your projects depends on and it will manage (install/update) them for you. But it manages them on a per-project basis and installing them in a directory inside your project.

Note: Composer is strongly inspired by Node.js’s “npm” and Ruby’s “bundler”.

Composer allows users to install PHP application that are available on “Packagist” which is its main repository containing available packages. Link: https://packagist.org.

What does composer do?

Suppose:

  • You have project that depends on a number of libraries.
  • Some of those libraries depend on other libraries.

Composer:

  • It enables you to declare the libraries you depend on.
  • Finds out which version or packages need to be installed, and it downloads them into your project.

Basic Commands

Composer offers several commands parameters including:
1) require: this command add the library in parameter to the file “composer.json” and install it.
2) install: this command install all libraries from “composer.json”, and use to download all PHP repository dependencies.
3) update: update all libraries form “composer.json”.
4) remove: uninstall a library and remove it from “composer.json”.

Supported Framework

  • Laravel (version 2 and later)
  • Symfony (version 4 and later)
  • CodeIgniter (version 3.0 and later)
  • CakePHP (version 3.0 and later)
  • FuelPHP (version 2.0 and later)
  • Drupal (version 8 and later)
  • TYPO3 (version 6.2 and later)
  • SilverStripe (version 3.0 and later)
  • Magento (version 2.0 and later)
  • Yii (version 1.1 and later)
  • Zend Framework (version 1 and later)
  • Silex (web framework)
  • Lumen (web framework)

System Requirements:

  • Composer requires PHP 5.3.2 or latest version to run on your machine.
  • Composer is multi-platform and it run equally well on Linux, Windows, and macOS.
  • A few PHP sensitive php settings and compile flags are also required, but when using installer you will be warned about any incompatibilities.

How to use it with Laravel?

Basically, to work in the Laravel framework you have to install the composer first. Without composer Laravel framework does not work. So, before using Laravel, make sure you have composer install on your machine.

Installing Composer

Installing Composer is easy. You can get information about installing composer at https://getcomposer.org/.

After download and run composer-setup.exe. It will install the latest Composer version and set up your PATH so that you can call “composer” from any directory in your command line.

Fig (a): Options in composer

In Laravel, composer commands are used for creating the project, as well as used for update the laravel version, clear cache, upgrade and for other work as per requirement.

Fig (b): Available commands in Composer

For creating the Laravel project, type the command in your terminal “composer create-project –prefer-dist laravel/laravel projectname”. Without Composer command, Laravel project will not create.

For example

© 2023 aynsoft.com - Website Development, Software Development Company India