Using Composer Without Framework

Composer is the de facto tool for managing dependencies in PHP. Even if you eschew frameworks, you can still reap its benefits by using it for autoloading and pulling in well‑maintained libraries.

1. Initialize your project

Run composer init in your project directory to create a composer.json. Define your package metadata and specify your PHP version.

2. Require packages

Use composer require vendor/package to add libraries. Composer will install them into the vendor directory and update your composer.json.

composer require monolog/monolog

3. Autoload your code

Define PSR‑4 autoloading rules in composer.json so your classes are loaded automatically. Include vendor/autoload.php in your entry point.

// in composer.json "autoload": { "psr-4": { "App\\": "src/" } }

After editing, run composer dump-autoload to regenerate the autoloader. Now you can focus on your application rather than boilerplate.