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
December 21, 2025
0.0k0

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

Step 1: Install Composer

Download from getcomposer.org and verify:

```bash composer -V ```

Step 2: Create composer.json

```bash composer init ```

Step 3: Set PSR-4 autoload

In `composer.json`:

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

Then run:

```bash composer dump-autoload ```

Step 4: Use autoload

```php <?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