• Skip to main content
  • Skip to primary sidebar

Technical Notes Of
Ehi Kioya

Technical Notes Of Ehi Kioya

  • Forums
  • About
  • Contact
MENUMENU
  • Blog Home
  • AWS, Azure, Cloud
  • Backend (Server-Side)
  • Frontend (Client-Side)
  • SharePoint
  • Tools & Resources
    • CM/IN Ruler
    • URL Decoder
    • Text Hasher
    • Word Count
    • IP Lookup
  • Linux & Servers
  • Zero Code Tech
  • WordPress
  • Musings
  • More
    Categories
    • Cloud
    • Server-Side
    • Front-End
    • SharePoint
    • Tools
    • Linux
    • Zero Code
    • WordPress
    • Musings
Home » Backend (Server-Side) » How To Install PHP Packages Without Composer

How To Install PHP Packages Without Composer

Last updated on September 10th, 2020 at 01:12 pm by Ehi Kioya 2 Comments

My previous article discussed the pros and cons of package managers like Composer and npm. The cons listed in that article (combined with a few of my personal frustrations) are the primary reasons why I think an article like this one is necessary.

Let me quickly reiterate one of the major cons of package managers and then get to the point: Bypassing Composer.

The Problem

Software development is my profession. And there are times when I really couldn’t do without a package manager. But there are also times when I would rather not use them. It depends on many different factors.

Package managers have an associated learning curve that may be too steep for an amateur developer who just wants to use a tiny code library.

There are lots of people who play with PHP without necessarily being professional programmers. PHP allows such people to do insane things even though they have never had to learn SSH or Composer or some other fancy package manager.

For such people, package managers contribute to further raising the barrier to entry into the already complex industry of software development.

Even for professional programmers, there are often situations where using Composer may be overkill.

Below, I explain two methods of bypassing the Composer barrier and installing Composer-dependent PHP packages without actually using Composer. For most people, I highly recommend the first method. It’s a lot faster.

But first, let’s look at an example of a github PHP package where our no-Composer techniques can be applied.

Example Scenario

Let’s say you want to use this LinkedIn API client package (just a random example – there are tons of other Composer-only github packages).

As of this writing (September 11, 2019), you will notice that the only way of installing the package is via Composer using this command:

composer require zoonman/linkedin-api-php-client

After which you can then include the autoloader with this line of code:

include_once __DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';

Note that the above autoloader include code references the vendor folder. If you try to download the zip from github directly, you will not find the vendor folder anywhere because it only gets created for you when you run the composer require command.

This means you first have to install Composer on the machine you’re working with. You may just not want to do this.

Ok, now, let’s bypass Composer…

Method 1: Using PHP-Download.com To Install PHP Packages Without Composer

This is the simplest method.

The website php-download.com helps you download all the dependencies of a PHP package along with the vendor folder.

Technically speaking, the site still uses Composer under the hood. But you don’t really have to care about how it does its magic. It gives you a zip file output that you can immediately unzip and consume without needing to install anything.

From the website’s homepage, enter the name of the github package you’re looking for. For example, enter zoonman/linkedin-api-php-client and do a search.

Installing PHP Packages Without Composer (Example zoonman LinkedIn API client)

The download page allows you to chose if you want a “require” option or if you want to “create project”. Most people would probably want to use the “require” option. If you’re working with a PHP framework like Laravel or CakePHP, you may want to explore the “create project” option.

When you select “require”, the site uses Composer under the hood to put all of the library’s dependencies together into a neat zip file that includes the vendor folder, autoload.php, etc.

Press download to get the zip file. Now, you can include these in your project normally.

Method 2: Manually Installing PHP Libraries Without Composer

Each github package that depends on Composer contains a composer.json file that lists the requirements (dependencies) of the package.

In the case of our LinkedIn API client package above, the requirements are:

"require": {
	"php": ">=5.6",
	"ext-curl": "*",
	"guzzlehttp/guzzle": "^6.3"
}

To manually install a package without Composer, you must find these required packages yourself in the packagist site.

Each dependency package may also have it’s own extra dependency and so on.

Repeat the process for each dependency down the chain by looking in their corresponding composer.json files and then searching again on the packagist website.

Once you have gotten a complete list of the needed packages, you now need to install them one by one. For the most part, this will be a matter of dropping the files somewhere in your project folder and then ensuring that PHP can find the needed classes.

Since you’re trying to bypass Composer’s autoloader, you will need to add these files to your own custom autoloader. The individual composer.json files can help you figure out the autoloader information.

Like this:

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

If you don’t want to use a class autoloader, you will need to figure out the individual require_once statements yourself. This may not be too easy (may involve some trial and error) because library authors hardly ever bother documenting that information.

Conclusion

I highly recommend Method 1 above.

As for Method 2, when you consider the amount of manual work involved in getting it to work, you may conclude that it makes more sense to use Composer after all. And I think I’d agree with that.

I included Method 2 (manual method) mostly for information purposes. It helps you understand some of what Composer does for you behind the scenes and why it has become so popular among PHP developers.

No package manager is perfect. But at this time, Composer is currently still the best at what it does.

Do you use Composer? Have you ever had to bypass Composer using that php-download website? Or some other (maybe even faster) technique? Please share your thoughts below. I’d really love to hear them.

Found this article valuable? Want to show your appreciation? Here are some options:

  1. Spread the word! Use these buttons to share this link on your favorite social media sites.
  2. Help me share this on . . .

    • Facebook
    • Twitter
    • LinkedIn
    • Reddit
    • Tumblr
    • Pinterest
    • Pocket
    • Telegram
    • WhatsApp
    • Skype
  3. Sign up to join my audience and receive email notifications when I publish new content.
  4. Contribute by adding a comment using the comments section below.
  5. Follow me on Twitter, LinkedIn, and Facebook.

Related

Filed Under: Backend (Server-Side), Frontend (Client-Side), PHP, Programming, Web Development Tagged With: Composer, Dependency Management, Package Managers, PHP

About Ehi Kioya

I am a Toronto-based Software Engineer. I run this website as part hobby and part business.

To share your thoughts or get help with any of my posts, please drop a comment at the appropriate link.

You can contact me using the form on this page. I'm also on Twitter, LinkedIn, and Facebook.

Reader Interactions

Comments

  1. Kris says

    March 23, 2020 at 10:11 am

    This was awesome! Thank you.

    Reply
  2. Kwabena says

    December 3, 2020 at 5:05 am

    Insightful article!!
    Thanks for sharing

    Reply

Leave a Reply Cancel reply

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

Primary Sidebar

25,822
Followers
Follow
30,000
Connections
Connect
14,617
Page Fans
Like

POPULAR   FORUM   TOPICS

  • How to find the title of a song without knowing the lyrics
  • Welcome Message
  • How To Change Or Remove The WordPress Login Error Message
  • The Art of Exploratory Data Analysis (Part 1)
  • Replacing The Default SQLite Database With PostgreSQL In Django
  • How to Implement Local SEO On Your Business Website And Drive Traffic
  • Getting Started with SQL: A Beginners Guide to Databases
  • Installing Facebook Pixel on Your Business Website
  • The Rise of the No Code Movement
  • WordPress vs Blogger – Pros and Cons
  • Recently   Popular   Posts   &   Pages
  • Actual Size Online Ruler Actual Size Online Ruler
    I created this page to measure your screen resolution and produce an online ruler of actual size. It's powered with JavaScript and HTML5.
  • Allowing Multiple RDP Sessions In Windows 10 Using The RDP Wrapper Library Allowing Multiple RDP Sessions In Windows 10 Using The RDP Wrapper Library
    This article explains how to bypass the single user remote desktop connection restriction on Windows 10 by using the RDP wrapper library.
  • WordPress Password Hash Generator WordPress Password Hash Generator
    With this WordPress Password Hash Generator, you can convert a password to its hash, and then set a new password directly in the database.
  • Forums
  • About
  • Contact

© 2021   ·   Ehi Kioya   ·   All Rights Reserved
Privacy Policy