What is Composer?
Composer is the dependency manager used by modern PHP projects. It installs third-party libraries, resolves compatible versions, and generates an autoloader so your application can load classes without manually including every file.
Check the installation
php -v
composer --version
If Composer is not installed, follow the official installation instructions for your operating system. Make sure Composer uses the same PHP executable and extensions that your project requires.
Initialize a project
From your project directory, run:
composer init
Composer creates a composer.json file. This file describes the project and its dependencies.
Install a package
For example, to add a library:
composer require vendor/package
Composer downloads the package into vendor/ and updates composer.json and composer.lock.
Load installed classes
Include the generated autoloader once in your application bootstrap:
require __DIR__ . '/vendor/autoload.php';
Important project files
composer.json: dependency requirements and project metadatacomposer.lock: exact dependency versions selected for this projectvendor/: installed packages and generated autoload files
Commit composer.json and composer.lock to version control. Do not commit the vendor/ directory in most application projects; install dependencies during deployment with Composer.