Skip to content
Readerstacks logo Readerstacks
  • Home
  • Softwares
  • Angular
  • Php
  • Laravel
  • Flutter
Readerstacks logo
Readerstacks
Install Composer

What is composer and how to install composer?

Aman Jain, September 18, 2021September 21, 2021

Composer is a dependency manager tool for PHP. Using the composer we can manage the package dependency and version of the packages. Composer is different from npm (Node package manager) and apt-get because it only contain the dependency of project.

Composer creates a compose.json file to contain the information about the project and dependencies like packages, module etc. when we install the dependencies using the composer it creates a folder named as vendor and install dependencies there.

Let’s install the composer:

System Requirements

Composer requires PHP 5.3.2+ to run. Some additional seating are also required but composer will notify you when you use it.

Installation of composer in ubuntu and macOS   

Before start make sure you have enabled the PHP CLI, so check php versions first in command line.

php -v 

it should output like below:

PHP 7.3.1 (cli) (built: Jul  5 2021 15:13:35) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.3.1, Copyright (c), by Zend Technologies

if it’s now showing as above then you need to install the php first, you can read How to Install php, apache, mysql(Lamp) and phpmysadmin on Ubuntu.

Now, There is two way to install the composer 

  1. Locally
  2. Globally

1. Installing Composer Locally in project

Go to the project location and open the terminal or First open the terminal and then go to path of project.

Type below command

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

above command will download composer-setup.php in current directory

php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

Above Command will check the installer is not corrupted and verified.

php composer-setup.php

This will check the php.ini settings and warn you if its not correct. It will run above script to install the composer in directory.

php -r "unlink('composer-setup.php');"

delete the composer-setup file.

2. Installing Composer Globally

We already downloaded the composer.phar file in directory. If we want to use it globally then we need to move it into /usr/local/bin/ so it will be accessible globally.

sudo mv composer.phar /usr/local/bin/composer

There is few arguments which we can use

–install-dir

To install the composer in sepecific directory

Example:

php composer-setup.php --install-dir=bin

–filename

You can specify the filename (default: composer.phar) using the –filename option. Example:

php composer-setup.php --filename=composer

–version

Change the version of composer.

Example:

php composer-setup.php --version=1.0.0-alpha8

Screenshot 2021 09 18 at 9.47.23 AM
Composer version

Install composer in windows

As we installed the composer using the command line in the same way we can install in windows but in windows we have more simple way to install it using window executable installer.

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.

Related

Php

Post navigation

Previous post
Next post

Related Posts

Php How to Get Last Record With Group By in Laravel Eloquent

How to Get Last Record With Group By in Laravel Eloquent ?

September 7, 2022March 16, 2024

In this tutorial we will learn to get last record with group by in laravel eloquent. while working with group by in mysql its gives first record from the group by records that means if you have multiple record with same id and you want the most recent record or…

Read More
Php How to add column in laravel migration

How to Add Column in Existing Table Laravel migration ?

February 15, 2022June 30, 2022

Adding column to existing table are easy as creating a new table and adding columns to it. In laravel migration we can add new colum to existing table using the same method we used in create migrations . Major difference between creating new table and updating new table is Schema::create…

Read More
Php How to Use hasOne Relationship in Laravel

How to Use hasOne Relationship in Laravel with Example ?

February 27, 2022October 4, 2022

hasOne relationship in laravel is used to create the relation between two tables. hasOne means create the relation one to one. For example if a article has comments and we wanted to get one comment with the article details then we can use hasOne relationship or a user can have…

Read More

Aman Jain
Aman Jain

With years of hands-on experience in the realm of web and mobile development, they have honed their skills in various technologies, including Laravel, PHP CodeIgniter, mobile app development, web app development, Flutter, React, JavaScript, Angular, Devops and so much more. Their proficiency extends to building robust REST APIs, AWS Code scaling, and optimization, ensuring that your applications run seamlessly on the cloud.

Categories

  • Angular
  • CSS
  • Dart
  • Devops
  • Flutter
  • HTML
  • Javascript
  • jQuery
  • Laravel
  • Laravel 10
  • Laravel 11
  • Laravel 9
  • Mysql
  • Php
  • Softwares
  • Ubuntu
  • Uncategorized

Archives

  • May 2025
  • April 2025
  • October 2024
  • July 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • July 2023
  • March 2023
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Recent Posts

  • Understanding High Vulnerabilities: A Deep Dive into Recent Security Concerns
  • Understanding High Vulnerabilities in Software: A Week of Insights
  • Blocking Spam Requests with LaraGuard IP: A Comprehensive Guide
  • Enhancing API Development with Laravel API Kit
  • Exploring the Future of Web Development: Insights from Milana Cap
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version