In this guide, we will install Composer or PHP Dependency Manager in the window through the CMD (command line Manger) PHP on Windows 10. Also, you can use this guideline on any of the window operating system (window-XP,window7,window8,window10).
Composer is a PHP dependency manager that is used to install the PHP Libraries. You can find all the PHP packages list here.
Step1. Setup Localhost
Install the localhost on your computer. To make the localhost you can use any of the third-party localhost provider link xampp, wamp, lamp.
Run your localhost
Step2. Download the composer
You can install the composer by two way
- Download composer.exe file and run with administrator
- You can also install the composer by cmd
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '8a6138e2a05a8c28539c9f0fb361159823655d7ad2deecb371b04a83966c61223adc522b0189079e3e9e277cd72b8897') { echo 'Installer verified'; } else { echo 'Installer corrupt';
unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
Step3. Now we have to use Composer
Your composer has been successfully installed you can check it by past this command in cmd
Composer
Now switch to your localhost root directory
Make a directory into the root folder
mkdir test
Now change the directory to test and install the package that you want. Here we will install the php timer package for demo
composer require phpunit/php-timer
Now make a php file demo.php
And past this code and hit the file in chrome
<?php
require __DIR__ . '/vendor/autoload.php';
use SebastianBergmann\Timer\Timer;
$timer = new Timer;
$timer->start();
foreach (\range(0, 100000) as $i) {
// ...
}
$duration = $timer->stop();
var_dump(get_class($duration));
var_dump($duration->asString());
var_dump($duration->asSeconds());
var_dump($duration->asMilliseconds());
var_dump($duration->asMicroseconds());
var_dump($duration->asNanoseconds());
Thank You! Your composer has been successfully installed and Used.