This tutorial helps to install Composer into your system. The PHP Composer is a powerful dependency manager for PHP projects. It helps to adding, managing, and updating libraries and packages in your project.
You can use Composer as a dependency manager for web applications, a content management system, or any PHP-based project, It helps to automate the management of your project’s dependencies.
You can also read: How to Uninstall Composer in Windows 10/11
Let’s walk you through the step-by-step process of installing PHP Composer on your system.
Step 1: Prerequisites
There are the following prerequisites in place to install Composer:
You need to requires PHP to be installed on your system. You can check if PHP is installed by opening a terminal or command prompt and run the below command:
php -v
If PHP is not installed, you’ll need to install it. You can download PHP from the official PHP website https://www.php.net/downloads.php.
apt
.Brew
package manager.Step 2: Verify the Installer
The Composer is distributed as a PHP script, and you can download it using the following command:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
The above command will download the Composer installer script (composer-setup.php
) to your current directory.
Step 3: Verify the Installer
You can verify its SHA-384 hash with the expected hash from the Composer website https://composer.github.io/pubkeys.html
php -r "if (hash_file('sha384', 'composer-setup.php') === 'EXPECTED_HASH_HERE') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
Replace ‘EXPECTED_HASH_HERE‘ with the hash you obtained from the Composer website. The above command will compare with the actual hash of the downloaded installer script.
Step 4: Run the composer Installer
We have already installed composer and navigated to that location and run the below command:
php composer-setup.php
The above command will install Composer globally on your system and make it available system-wide.
You can make Composer globally accessible from the command line in Linux or macOS. You need to move the Composer executable to a directory in your system’s PATH. You can use the following command:
sudo mv composer.phar /usr/local/bin/composer
You need to set composer.phar
file path in your system’s PATH, such as C:\Windows\System32.
To verify that Composer has been successfully installed, open a new terminal or command prompt window and run the following command:
composer --version
You can update the composer using the below command:
composer self-update
The above command will fetch the latest version of Composer and update it on your system.
We’ve walked you through the step-by-step installation of PHP Composer on your system. The Composer is a powerful tool that will help you manage dependencies in your PHP projects. You can manage PHP project package dependencies and seamlessly transfer projects between different systems without concerns about package versions.
This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More
in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More
This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More
We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More
in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More
I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More