How7o
  • Home
  • Marketing
    MarketingShow More
    The Beginner’s Guide about Facebook Advertising
    6 Min Read
    64 Creative Marketing Ideas to Boost Your Business
    6 Min Read
  • OS
    OSShow More
    How to force quit frozen apps in Ubuntu
    Force Close an App in Ubuntu (xkill, System Monitor, kill -9)
    4 Min Read
  • Features
    FeaturesShow More
  • Guide
    GuideShow More
    Tips to Keep Your Cloud Storage Safe and Secure
    6 Min Read
  • Contact
  • Blog
Reading: How to Include Composer Packages in Plain PHP Projects (Autoload + Example)
Share
Subscribe Now
How7oHow7o
Font ResizerAa
  • Marketing
  • OS
  • Features
  • Guide
  • Complaint
  • Advertise
Search
  • Categories
    • Marketing
    • OS
    • Features
    • Guide
    • Lifestyle
    • Wellness
    • Healthy
    • Nutrition
  • More Foxiz
    • Blog Index
    • Complaint
    • Sitemap
    • Advertise
Follow US
Copyright © 2014-2023 Ruby Theme Ltd. All Rights Reserved.
How7o > Blog > 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.
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 The Beginner’s Guide about Facebook Advertising
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

Your email address will not be published. Required fields are marked *

FacebookLike
XFollow
PinterestPin
InstagramFollow

Subscribe Now

Subscribe to our newsletter to get our newest articles instantly!
Most Popular
How I Fixed Composer Dependency Errors
How I Fixed Composer Dependency Errors Using the –ignore-platform-reqs Flag (Step-by-Step Guide)
January 12, 2026
Transfer Discourse to a new server
How to Transfer Discourse to a New Server on AlmaLinux (Backup + Restore, Step-by-Step)
January 12, 2026
Installed Discourse on AlmaLinux
How I Installed Discourse on AlmaLinux (Docker Method, Step-by-Step)
January 12, 2026
Installing Docker on AlmaLinux guide
Install Docker on AlmaLinux: Step-by-Step (Docker CE + Compose)
January 12, 2026
Change welcome message on Ubuntu VPS server (MOTD + SSH banner)
Change Welcome Message on Ubuntu VPS (MOTD + SSH Banner)
January 12, 2026

You Might Also Like

Debug PHP like console.log using error_log and server logs
Web Development

How to Debug in PHP Like console.log (echo, error_log, WordPress debug.log)

6 Min Read
WooCommerce homepage filter to hide out of stock products
Web Development

Hide Out of Stock Products from Homepage in WooCommerce (Keep Them Visible Elsewhere)

5 Min Read
Return or throw an error in Laravel (JSON response vs exception)
Web Development

How to Manually Return or Throw an Error Exception in Laravel

6 Min Read
Display only the current date in Laravel using Carbon
Web Development

How to Display Only the Current Date in Laravel (Carbon Examples)

4 Min Read

Always Stay Up to Date

Subscribe to our newsletter to get our newest articles instantly!
How7o

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

Latest News

  • SEO Audit Tool
  • Client ReferralsNew
  • Execution of SEO
  • Reporting Tool

Resouce

  • Google Search Console
  • Google Keyword Planner
  • Google OptimiseHot
  • SEO Spider

Get the Top 10 in Search!

Looking for a trustworthy service to optimize the company website?
Request a Quote
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?