How to install and use composer
How to install and use composer
- Install composer
- installing composer on hostinger shared hosting
$ vi composer-installer.sh
#!/bin/sh EXPECTED_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig) php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');") if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ] then >&2 echo 'ERROR: Invalid installer signature' rm composer-setup.php exit 1 fi php composer-setup.php --quiet RESULT=$? rm composer-setup.php
$ sh composer-installer.sh $ composer ______ / ____/___ ____ ___ ____ ____ ________ _____ / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/ / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ / \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/ /_/ Composer version x.x.x YYYY-mm-dd HH:MM:SS
- installing composer on Linux/MacOS
(local installation) $ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" $ php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" $ php composer-setup.php --install-dir=bin --filename=composer $ php bin/composer (global installation after local installation) $ sudo mv composer.phar /usr/local/bin/composer $ composer
- installing composer on Windows
Download the latest composer version, Install and Run
- installing composer on hostinger shared hosting
- Generating and understanding
composer.json
- Create a new directory and enter
$ mkdir phptimer $ cd phptimer
find a composer package or library at packagist
install
$ composer require phpunit/php-timer (composer will create two new files - `composer.json` and `composer.lock`)
Using autoload script
require 'vendor/autoload.php'
require 'vendor/autoload.php' PHP_Timer::start(); // your code $time = PHP_Timer::stop(); var_dump($time); print PHP_Timer::secondsToTimeString($time)
Updating your project dependencies
$ composer update $ composer update vendor/package vendor2/package2