How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: How to Include Composer Packages in Plain PHP Projects (Autoload + Example)
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Web Development > How to Include Composer Packages in Plain PHP Projects (Autoload + Example)
Web Development

How to Include Composer Packages in Plain PHP Projects (Autoload + Example)

how7o
By how7o
Last updated: January 14, 2026
5 Min Read
Include Composer packages in plain PHP projects
SHARE

I used to avoid Composer in “plain PHP” projects because I thought it was only for frameworks. Then I needed a small library (a subtitle converter) for a simple PHP script and tried the old-school approach: downloading random ZIP files, copying folders around, and manually requiring files.

Contents
  • What Composer does in a plain PHP project (quick explanation)
  • Step 1: Make sure Composer is installed
  • Step 2: Create your project folder
  • Step 3: Install a Composer package (composer require)
  • Step 4: Include vendor/autoload.php (this is the missing piece)
  • Step 5: Use the package (real working example)
  • Common mistakes (and quick fixes)
    • 1) “Failed to open stream: vendor/autoload.php”
    • 2) “Class not found”
    • 3) “It works locally but not on the server”
  • Bonus: Autoload your own PHP classes (PSR-4 style)
  • Final thoughts

It worked… until it didn’t. One missing file, one wrong include path, and suddenly I was stuck in “Class not found” hell.

That’s when I switched to Composer properly—and the fix was surprisingly simple: install the package with composer require, then load vendor/autoload.php once. After that, the package works like magic in a plain PHP project.

What Composer does in a plain PHP project (quick explanation)

Composer is a dependency manager for PHP. It downloads libraries into a vendor/ folder and generates an autoloader file (vendor/autoload.php) so you don’t have to manually include every class file.

Framework or no framework—Composer works the same.

Step 1: Make sure Composer is installed

On your server or local machine, check:

composer --version

If you see a version number, you’re good. If not, install Composer first (I usually install it globally so it’s available anywhere).

Step 2: Create your project folder

I like to start clean:

mkdir my-plain-php-project
cd my-plain-php-project

Create a basic entry file:

touch index.php

Step 3: Install a Composer package (composer require)

In your original example, the package was a subtitle converter:

composer require mantas-done/subtitles

After this, Composer will create (or update) these things inside your project:

  • composer.json (your dependency list)
  • composer.lock (locked versions for consistent installs)
  • vendor/ directory (downloaded packages)
  • vendor/autoload.php (the autoloader file you must include)

Step 4: Include vendor/autoload.php (this is the missing piece)

This is the part most people forget in plain PHP projects. If you don’t load the autoloader, PHP won’t know where the package classes live.

Open your index.php and add:

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

Why I use __DIR__: it prevents path problems when your script runs from a different working directory.

Step 5: Use the package (real working example)

Now you can use the library normally. Example: convert an .srt file to .vtt:

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

use Done\Subtitles\Subtitles;

// Convert subtitles.srt → subtitles.vtt
(new Subtitles())->convert('subtitles.srt', 'subtitles.vtt');

echo "Done! Converted to VTT.";

Put your subtitle file in the same folder as index.php (or use full paths), then run:

php index.php

Common mistakes (and quick fixes)

1) “Failed to open stream: vendor/autoload.php”

  • You didn’t run composer install / composer require in this project folder.
  • Your script is inside a subfolder (example: public/index.php), so the path should be __DIR__ . '/../vendor/autoload.php'.

2) “Class not found”

  • Autoloader is not included (add require __DIR__ . '/vendor/autoload.php';).
  • Namespace/class name is wrong (double-check the package docs).

3) “It works locally but not on the server”

Most of the time, it’s because you uploaded your project without the vendor/ folder. Best practice is:

  • Upload composer.json and composer.lock
  • Then run composer install --no-dev on the server

Bonus: Autoload your own PHP classes (PSR-4 style)

Once I started using Composer, I also stopped manually requiring my own class files. Here’s the clean approach:

  • Create a folder: src/
  • Put your classes in there with namespaces
  • Add an autoload rule in composer.json

Example composer.json snippet:

{
  "require": {
    "mantas-done/subtitles": "^1.0"
  },
  "autoload": {
    "psr-4": {
      "App\\": "src/"
    }
  }
}

Then regenerate the autoloader:

composer dump-autoload

Now you can use your own classes like use App\MyClass; without writing a bunch of require statements.

Final thoughts

If you remember only one thing: installing the package is not enough—you must include the autoloader. Once you add require __DIR__ . '/vendor/autoload.php'; at the top of your entry file (or a shared bootstrap.php), Composer packages work perfectly in plain PHP projects.

TAGGED:Autoloadcomposercomposer.jsonDependenciesPackagistphpPSR-4vendor

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article Remove Files & Folders in Linux How to Remove Files and Folders in Linux Using Command Line (rm, rmdir, unlink)
Next Article Install a specific version of a package using Composer (composer require vendor/package:2.1.0) Install a Specific Version of a Package Using Composer (Exact Version + Examples)
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Bun runtime — faster JS toolkit replacing npm in Laravel projects
How to Install Bun Runtime on Ubuntu (And Use It in a Laravel Project)
May 24, 2026
Tailscale mesh — peer-to-peer connections between devices, coordination server
How to Install Tailscale on Ubuntu (Zero-Config Mesh VPN for Self-Hosters)
May 24, 2026
Caddy server — automatic HTTPS, 3-line Caddyfile vs 25-line nginx config
How to Install Caddy Server on Ubuntu (Automatic HTTPS, Drop-in nginx Alternative)
May 24, 2026
Cloudflare Tunnel — outbound-only connection from server, no inbound port forward
How to Install Cloudflare Tunnel on Ubuntu (Expose Local Services, No Port Forwarding)
May 24, 2026
WireGuard encrypted tunnel between server and clients with lock icons
How to Set Up WireGuard VPN on Ubuntu (Server, Linux Client, and iOS)
May 24, 2026

You Might Also Like

Create custom exception class in Laravel (Artisan command + secure error handling)
Web Development

How to Create a Custom Exception Class in Laravel (With Clean JSON Responses)

6 Min Read
Set A4 paper size in CSS for printing
Web Development

How to Set A4 Paper Size in CSS for Print

5 Min Read
Laravel delete file from public folder — File::delete with public_path
Web Development

How to Delete Files from the Public Folder in Laravel

7 Min Read
Laravel global variable for views — View::share in AppServiceProvider and View::composer wildcard patterns
Web Development

How to Set a Global Variable for Laravel Views

7 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?