PHPPHP20 min read

Composer Basics (Dependencies + Autoload PSR-4)

Use Composer to install PHP packages and configure PSR-4 autoloading for your project.

Sophia Turner
October 4, 2025
3.5k73

Composer is like npm for PHP. It manages libraries and autoloading.

Step 1: Install Composer

Download from getcomposer.org and verify:

composer -V

Step 2: Create composer.json

composer init

Step 3: Set PSR-4 autoload

In composer.json:

{
  "autoload": {
    "psr-4": {
      "App\\": "src/"
    }
  }
}

Then run:

composer dump-autoload

Step 4: Use autoload

<?php
require __DIR__ . "/vendor/autoload.php";

use App\Models\User;

$user = new User("Emma Parker");
?>

Why Composer is important

Most modern PHP development depends on Composer for libraries, autoloading, and consistent setup.

Next: MVC pattern, the structure behind most PHP frameworks.

#PHP#Composer#Intermediate