Php

How To install PHP Composer in Linux/Windows

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

How to Install PHP Composer

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.

  • Linux: You can install PHP using a package manager like apt.
  • macOS: You can install PHP using the Brew package manager.
  • Windows: You can install PHP using XAMPP or WAMP.

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

Related Post
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.

Composer Globally Accessible on Linux

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

Composer globally accessible in Windows

You need to set composer.phar file path in your system’s PATH, such as C:\Windows\System32.

Verify the Installation

To verify that Composer has been successfully installed, open a new terminal or command prompt window and run the following command:

composer --version

How To Update Composer in Linux

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.

Conclusion

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.

Recent Posts

Configure and Retrieve S3 Information Using Laravel PHP-AWS-SDK

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

3 months ago

What is the Purpose of php_eol in PHP?

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

9 months ago

Laravel Table Relationship Methods With Example

This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More

9 months ago

Exploring the Power of Laravel Eloquent Join?

We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More

9 months ago

Quick and Easy Installation of Laravel Valet

in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More

10 months ago

What is Laravel Soft Delete and How Does it Work?

I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More

10 months ago

Categories