How to Install Composer on Windows

Composer is an application that is used for dependency management in standard format in PHP. Composer lets you declare the libraries on which your PHP project depends and manage it for you. It installs and updates the libraries that you need for your project.

By default, Composer doesn't install anything globally; it manages dependencies based on per-project and installs them in the directory (vendor) inside your project.

Composer offers two things for our projects:

  • Helps in dependency management for PHP.
  • Helps in file auto-loading in the project.

The Composer is highly energized by Node's NPM and Ruby's bundle.

Suppose a scenario:

  1. You have a PHP project which depends on several libraries.
  2. And some of these libraries also depend on other libraries.

Composer fulfills the requirement of the above scenario as:

  1. It lets you declare the libraries your project depends on.
  2. It finds out which versions of the package you require to install in your project, and it downloads and installs for you.
  3. It also allows updating all your dependencies in a single command.

System requirements to install Composer:

Composer requires installed and successfully running PHP 5.3.2+ on the machine. It also requires some sensitive PHP settings and compiles flags. Installing the Composer packages from source rather than zip archive, you will require git, svn, fossil or hg based on the package version-controlled. A Composer is a multi-platform tool that runs equally on Windows OS, Linux and macOS.

Install Composer on Windows

There are two ways to install Composer on the Windows operating system: the first one is using Composer installer setup, and the other is by manual installation using script.

1. Using Installer

a) Installing Composer using Composer installer setup is the easiest way to install it on Windows operating system. Launch your default browser and visit https://getcomposer.org and click on the "Getting Started" button. Under the "Installation - Windows" section, click on the "Using the Installer" option; it will take you to the "Using the Installer" section.

How to Install Composer on Windows

b) Click on the Composer-Setup.exe link to download Composer setup on your device. After downloading the setup, run it to install and follow the instructions.

c) Open the downloaded Composer-Setup and click on the "Install for all users", which is recommended option to install Composer setup.

How to Install Composer on Windows

d) On the pop-up screen, click on YES to allow installation.

e) Now, choose your installation type and click on the Next

How to Install Composer on Windows

f) Now, choose the command-line PHP path you want to use, checkmark the box to add the PHP path, and click Next.

How to Install Composer on Windows

g) Composer setup pop-up a screen that provides an option to use a proxy server to connect to the internet. If you want to use a proxy server, checkmark the box and enter the proxy URL; if not, leave it and click on the Next We are skipping this as we are not using any proxy server to connect internet.

How to Install Composer on Windows

h) The Composer setup is ready to install on your computer; review your settings and click on the Install button.

How to Install Composer on Windows

i) After installation of Composer setup, it pop-up important information about how to open it. Read the information, click on Next and do accordingly after installation.

How to Install Composer on Windows

j) Click on the Finish button to complete the installation.

How to Install Composer on Windows

When the Composer gets installed on your machine, open command (cmd) windows, type composer and press Enter key. If it displays a list of commands, that means Composer is successfully installed on your computer.

How to Install Composer on Windows

2. Manual Installation

You can install Composer at any directory where you want. In our case, we are installing at C:\xampp\htdocs\composersetup directory. Open your command (cmd) terminal and go to the directory location you want to install (C:\xampp\htdocs\composersetup).

Copy and paste the following script in your cmd terminal and run it to install Composer. It will automatically install the latest Composer to your current directory.

This installer script just checks the php.ini settings. If settings are set incorrectly, it will warn you and start downloading the latest composer.phar in the current directory (C:\xampp\htdocs\composersetup). If the installation gets successful, you will see a message of successfully installed.

How to Install Composer on Windows

The above 4 scripting lines must be in order that performs the following activities:

  • Download the composer installer to the current directory.
  • Verify the composer installer SHA-384 certificate.
  • Run the composer installer.
  • Remove the composer installer.

Note: The script code may get change based on the new version released. To check the script for installing a new release of Composer, visit https://getcomposer.org/download/.

Note: If the script throws an error that "php is not recognized as an internal or external command". Then check the PHP path is well set in computer Environment Variables settings or not. To set PHP path globally for your machine, copy the php path where it is located (C:\xampp\php), and past it, at Advanced system settings,> Environment Variables > select Path and click on New. Now, in the Variable Name type Path and in the Variable Value, paste the php location, i.e., C:\xampp\php.

You can check your installed composer version using a command composer -v at the current path. Such as:

For example:


How to Install Composer on Windows

Here, we get installed Composer's current version 2.0.8 on our machine.

Create a new composer.bat file in the same directory where the composer.phar is present.

Using cmd


How to Install Composer on Windows

Using PowerShell


How to Install Composer on Windows

Some of the other notable installer options of Composer

--install-dir

You can install Composer in a particular directory where you want using the --install-dir option and providing the target directory name. For example:

--filename

You can even specify the filename other than its default name (composer.phar) using the --filename option. For example:

--version

Composer allows installing its particular release using the --version option along with providing a specific release version. For example:

--help

Using the --help option, you can view various composer options for a specific environment. For example:

Updating and Uninstalling Composer

If you want to updates your Composer or uninstall any of its dependency managers, make sure you have Git for Windows installed on your machine. From there, you can verify Composer's installation by running --version command from the terminal. If the command returns the version code, it means the Composer is installed, and you are ready for the next steps.

Before updating your Composer, check its current version that is installed on your computer. You can do this by typing the following command in your terminal application:

or

Update Composer

To update Composer itself, run the below script, and it will update the Composer.

Update Dependency

As Composer manages the dependencies library of your project, you can update these dependencies if required for you using the below command:

If you don't have an active project running with Composer's dependencies on your current directory, Composer shows a message that it was unable to find a composer.json file.

Uninstall packages

To uninstall the packages from Composer, run the below command:

Make sure to replace "your_package_name" with the actual package name in the above command. It will uninstall the package from Composer.


Next TopicPHPMyAdmin Login




Contact US

Email:[email protected]

How to Install Composer on Windows
10/30