PHP 101
  • Home
  • Deploy
  • How-to
  • Tutorial
No Result
View All Result
PHP 101
  • Home
  • Deploy
  • How-to
  • Tutorial
No Result
View All Result
PHP 101
No Result
View All Result
Home Tutorial

How to install Composer on Windows

In-depth tutorial on how to install Composer and make it works properly on Windows.

March 8, 2022
Reading Time: 5 mins read
PHP101.net - Tutorial - Install Composer on Windows

PHP101.net - Tutorial - Install Composer on Windows

Share on FacebookShare on Twitter

Table of Contents

    • Introduction
    • What is Composer?
    • Install Composer on Windows – Step by step
    • 1. System requirements for Composer on Windows
    • 2. Download Composer on Windows
    • 3. Installing Composer
    • 4. Verify Composer installation
    • 5. Update Composer on Windows
    • Example Usage
    • Final thoughts
    • You might also like
    • References

Don’t like the intro? Skip to the Tutorial here.

Introduction

A long time ago, to include an external PHP library into a PHP development project, you had to:

  • Download the PHP library (in zipped format);
  • Extract it into a directory inside the project;
  • Include it using a require_once function;

That was the process. When deploying your project, you have to upload everything including the library files. And when a package gets an update? You download it, extract, overwrite the files, all over again.

That’s why Composer is a savior for PHP developers, or in short, Composer is a PHP dependency manager.

What is Composer?

As the above introduction, Composer is a PHP dependency manager, which greatly helps the PHP development process. Its main functionalities are:

  • Install, include, update PHP dependency libraries in a project quickly;
  • Declare dependencies in a PHP package/project easily;

Whether you have a project depends on other libraries, and some of the libraries also depend on other libraries, Composer can handle this easily!

In Official Composer Introduction page, Composer can:

  1. Enables you to declare the libraries you depend on.
  2. Finds out which versions of which packages can and need to be installed, and installs them (meaning it downloads them into your project).
  3. You can update all your dependencies in one command.

Therefore, it’s a no-brainer to use Composer in your PHP development.

Composer supports both Windows, Linux and MacOS. This in-depth article will guide you on how to install Composer on Windows operating system.

Tutorial StartsInstall Composer on Windows – Step by step

As any other softwares, Composer has its own system requirements too.

1. System requirements for Composer on Windows

  • You have PHP installed -OR- you have PHP package downloaded already with executable file (php.exe).

We have an in-depth tutorial on how to download and install PHP on Windows:

How to install PHP on Windows – Standalone method

Latest Composer requires at least PHP 7.2.5 to run. If you run legacy PHP version (but still at least requires PHP 5.3.2), there are old Composer versions, but it will pose many incompatibilities issues, so we don’t recommend using legacy versions.

2. Download Composer on Windows

Composer makes it very straightforward to download and setup on your Windows system. To download the latest version, head to the official Composer Windows package download URL:

https://getcomposer.org/Composer-Setup.exe

https://getcomposer.org/Composer-Setup.exe

3. Installing Composer

Run the Composer-Setup.exe file that you just downloaded.

First, you will choose the Install Mode. It’s recommended to install for all users if you have administrator privilege. But if not, you can just install for your account, Composer can still run normally.

PHP101.net - Tutorial - Installing Composer on Windows
Select install mode

Next, if you choose Developer mode, there will be no uninstaller included. It’s up to you on this one.

PHP101.net - Tutorial - Installing Composer on Windows
Specify if Developer mode is enabled

Choosing php.exe executable path is required on the next step. This is the path where PHP is installed on your system. If there is one installed, Composer will automatically detect it, else you can manually Browse… and specify the file location.

PHP101.net - Tutorial - Installing Composer on Windows
Specify PHP installation/executable path

Specify if you are using any proxy enabled for browsing the Internet.

PHP101.net - Tutorial - Installing Composer on Windows
Proxy configuration

This Ready to Install screen will have the main configuration displayed for you to check before the installation start. Click Install when everything is good.

PHP101.net - Tutorial - Installing Composer on Windows
Installation configuration before installing

The installation will start. You will see these screens when the installation is finished:

PHP101.net - Tutorial - Installing Composer on Windows
Composer installation finished

Now the installation is done. In summary, this installation will:

  • Download the latest composer.phar file from Composer server;
  • Copy it and the configuration files, the uninstaller (if checked) into your user’s \AppData\Local\ComposerSetup\ folder (in your user mode) or C:\ProgramData\ComposerSetup\ folder (all users mode);
  • Add Composer into Windows Environment Variables so it can be run from command lines.

We will verify the installation on the next step.

4. Verify Composer installation

To check if Composer has been probably installed, open any Windows terminal tools (cmd.exe, PowerShell, VSCode terminal, etc.) and enter this command:

composer --version

Alternatively, composer -V (V in capitalized) is the same command. If this similar message returns, Composer has been successfully installed:

C:\Users\php101dotnet>composer -V
Composer version 2.0.14 2021-05-21 17:03:37

5. Update Composer on Windows

To update Composer on Windows, you can just follow the steps above to download the latest Composer and install it again, which will update Composer to the latest version.

Example Usage

This is a quick example Composer usage to show how easy it is (but also powerful).

Assuming we have an empty PHP project that needs URL slug functionality which turns text into slug URL for SEO purposes (eg. an example project to an-example-project). Instead of writing this functionality from scratch, we will use the ausi/slug-generator library written by GitHub user ausi, which is already perfect to do that.

On the (empty) PHP project folder, use the terminal and enter this command:

composer require ausi/slug-generator

This Composer command will:

  • Download the ausi/slug-generator package which is located on Packagist.org – the main Composer package repository
  • Install it into our PHP project directory under the vendor folder,
  • Add the package information at composer.json file
  • Record the version, time, hashes into composer.lock file to keep track of the packages’ states
  • Handle all library inclusion into vendor\autoload.php file

Graphical views of the package installation after running the command:

PHP101.net - Tutorial - Installing Composer on Windows
Folder layout after installing Composer package

That is very handy, compared to downloading the package manually and copying it. So to use the package, we just have to include the autoload.php file. For example on our project:

<?php

// Include all Composer vendor libraries
require_once('./vendor/autoload.php');

// Include Slug library
use Ausi\SlugGenerator\SlugGenerator;

// Start using it!
$generator = new SlugGenerator;
echo $generator->generate('php101.net Composer installation example'); 

// Output: php101-net-composer-installation-example

As you see, it is extremely convenience to use Composer for PHP projects.

Final thoughts

This marks the end of our tutorial on how to install Composer on Windows for PHP dependency management. With PHP development, knowing how to use Composer is a must.

We will constantly update this article with new information, as well as releasing other articles with more helpful Composer use cases.

Thanks for reading and hopefully this tutorial is helpful for you.

You might also like

  • PHP installation on Windows – Standalone method

References

  • Composer official website
  • Packagist.org for PHP packages
Tags: composer on windowsinstall composerinstall composer on windowspackagist.orgphp composer on windows
Previous Post

How to install PHP GeoIP extension & GeoLite2 library (databases included)

Next Post

How to install Composer on Linux

Related Posts

PHP101.Net - Tutorial - Change Laragon PHP version on Windows

How to change Laragon PHP version on Windows

September 21, 2022
PHP101.Net - Tutorial - Install ImageMagick on Windows

How to install ImageMagick on Windows

September 9, 2022
Next Post
PHP101.net - Tutorial - Install Composer on Linux

How to install Composer on Linux

We deliver free and helpful resources for learning
and using PHP programming language.

About
Contact Us
Privacy Policy
Main Sections

Home
Deploy
How-to
Tutorial
You might be interested in...

Deploy a webserver with XAMPP on Windows for PHP development

4 ways to increase PHP memory limit

How to get user IP address using PHP

How to convert from array to string in PHP

How to copy files using PHP

© 2022 PHP101.Net - Helpful PHP Tutorials, How-to, Tips and Tricks for everyone.

No Result
View All Result
  • Home
  • Deploy
  • How-to
  • Tutorial

© 2022 PHP101.Net - Helpful PHP Tutorials, How-to, Tips and Tricks for everyone. | Privacy Policy

This website uses cookies. By continuing to use this website you are giving consent to cookies being used. Visit our Privacy and Cookie Policy.