How To Install COMPOSER in AWS EC2 (Amazon Linux 2 )

What is Composer?

PHP Composer is a dependency manager for PHP. It allows you to declare the libraries your project depends on and it will install and manage them for you.

A composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

Using Composer can help you avoid having to manually download and manage libraries and their dependencies, which can save you time and help ensure that your project is using consistent, up-to-date versions of the libraries it depends on.

How To Install on AWS EC2 instance ( Amazon Linux 2 )

cd ~
sudo curl -sS https://getcomposer.org/installer | sudo php
sudo mv composer.phar /usr/local/bin/composer
sudo ln -s /usr/local/bin/composer /usr/bin/composer

#then you can run 
sudo composer install

How To Use Composer?

To use Composer, you will need to have PHP installed on your system. You can then install Composer by following the instructions on the Composer website (https://getcomposer.org). Once you have Composer installed, you can use it to install libraries for your project by creating a composer.json file that lists the libraries your project depends on, and running the composer install command.

For example, let’s say you want to use the popular PHP testing library PHPUnit in your project. To do this using Composer, you would first create a composer.json file that looks like this:

{
    "require": {
        "phpunit/phpunit": "^9.0"
    }
}

This file declares that your project depends on the PHPUnit library, specifically version 9.0 or higher.

Next, you would run the composer install command, which will install PHPUnit and its dependencies into a vendor directory in your project. You can then include the PHPUnit autoloader in your project and start using the library.

Composer makes it easy to manage the libraries your project depends on and helps ensure that you are using consistent, up-to-date versions of those libraries. It is a valuable tool for any PHP developer.

Leave a Comment

Your email address will not be published. Required fields are marked *