Composer
Composer is a popular package manager for PHP. It's used to install packages (libraries/frameworks/...) rather seamlessly.
- π Documentation
- π Installation
- ποΈ packagist (to find packages)
$ sudo apt install composer
Composer uses a composer.json
to track which libraries have to be installed, and which versions can be downloaded/installed, based on rules defined by the user (see versions).
Downloaded packages are stored in vendor/
.
To use libraries inside vendor
in your script, you need to import them using the autoloader:
require_once __DIR__ . '/vendor/autoload.php;
- To create a
composer.json
, usecomposer init
. - To generate
vendor/
from an existingcomposer.json
$ composer install # install all dependencies
$ composer install --no-dev # aside from dev dependencies
- To add new packages to
composer.json
and install them, use
$ composer require package
$ composer require vendor/package
$ composer require vendor/package:version
$ composer require --dev [...] # save as dev dependency
Installing packages will generate a composer.json.lock
. This file keeps track of the exact version of packages inside vendor/
. You can use composer update
to update them.
β‘οΈ Note that packages are updated according to the ranges/rules defined in composer.json
, so even if a package has updates, it may not be updated, if the update is not within the allowed range.
π» To-do π»
Stuff that I found, but never read/used yet.
-
composer require --dev
-
php composer.phar -v
(no install required)