Technical Documentation Site

Version 0.9.0

Technical Cheat Sheets

Composer

Install Composer

composer installation doc

https://getcomposer.org/download/

You can run the installation from the user home folder or any other directory. On mac you can go to the user home directory with:

cd ~

or

cd /Users/username
Download the installer to current directory
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

this will install composer-setup.php to your current directory

Verify the installer SHA-384
php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

Installer verified

Run the installer
php composer-setup.php

All settings correct for using Composer Downloading…

Composer (version 2.1.3) successfully installed to: /Users//composer.phar Use it: php composer.phar

Remove the installer
php -r "unlink('composer-setup.php');"

composer-setup.php file is removed from your current directory

Upgrade Composer

cd into directory that contains composer.phar file

cd /usr/local/bin

update composer to latest version

php composer.phar self-update

this will replace composer.phar with the latest version

to update to a specific release:

php composer.phar self-update n.n.n

replace n.n.n to a version number you would like to update to

If update fails remove the old version of composer manually and install the latest verison

Remove older version of composer

cd into the user home directory and rename old .composer file

mv .composer dot_composer_bak

cd into /usr/local/bin and rename old composer.phar

mv composer.phar composer_phar_bak
Commands

https://getcomposer.org/doc/03-cli.md

composer version
composer -v
list available composer commands
composer list
list packages

list installed packages

composer show -i

list all packages (available and installed)

composer show
install a package

Adds required packages to composer.json and installs them

composer require <package-name>
Composer Versions

https://getcomposer.org/doc/articles/versions.md

Example of version constraints for a package( vendor/package in this example ) declared in composer.json

"require": {
    "vendor/package": "1.3.2", // exactly 1.3.2

    // >, <, >=, <= | specify upper / lower bounds
    "vendor/package": ">=1.3.2", // anything above or equal to 1.3.2
    "vendor/package": "<1.3.2", // anything below 1.3.2

    // * | wildcard
    "vendor/package": "1.3.*", // >=1.3.0 <1.4.0

    // ~ | allows last digit specified to go up
    "vendor/package": "~1.3.2", // >=1.3.2 <1.4.0
    "vendor/package": "~1.3", // >=1.3.0 <2.0.0

    // ^ | doesn't allow breaking changes (major version fixed - following semver)
    "vendor/package": "^1.3.2", // >=1.3.2 <2.0.0
    "vendor/package": "^0.3.2", // >=0.3.2 <0.4.0 // except if major version is 0
}
Last updated on 19 May 2021
Published on 19 May 2021
Edit on GitHub