라이브러리
주요코인시세(KRW)
BTC %
ETH %
XRP %
ADA %
DOGE %
※ 업비트 시세 기준
XRPL Account Lines
XRPL Account Offers
XRPL Account Currencies

[PHP] How To Install PHP Packages Without Composer

관리자 2020.07.27 23:50 조회 수 : 104

https://ehikioya.com/how-to-install-php-packages-without-composer/

 

 

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:

1
2
3
4
5
"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:

1
2
3
"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.

번호 제목 조회 수
29 [JS기타] cdnjs 58
28 [JS라이브러리] Owl Carousel 2 file 70
27 [CSS] 어썸폰트 CDN(사파리에도 출력됨) 53
26 [JS라이브러리] FlexSlider 2 file 64
25 [CSS] CSS Gradient 61
24 [JS라이브러리] SPLIDE file 61
» [PHP] How To Install PHP Packages Without Composer 104
22 [PHP] PHP-Download.com 48
21 [PHP] PayPal-Checkout-PHP-SDK 43
20 [HTML소스] w3schools.com 45
19 [JS기타] jQueryScript.Net 59
18 [HTML테마] colorlib - HTML & Bootstrap Website Templates 67
17 [HTML테마] Free HTML Website Templates 66
16 [HTML테마] Free One Page Templates 229
15 [소셜로그인] Google Sign-In(구글소셜로그인) 137
14 [JS라이브러리] Adaptor - Cool 3D jQuery Content Slider Plugin file 55
13 [JS라이브러리] jQuery Plugin For 360 Degree 3D Panoramic View - 3dEye.js file 69
12 [JS라이브러리] Simple jQuery Star Rating System For Bootstrap 3/4 file 56
11 [JS라이브러리] Animating Numbers Counting Up with Counter-Up Plugin file 52
10 [JS라이브러리] Export Html To Word Document With Images Using jQuery Word Export Plugin file 160
9 [JS라이브러리] jQuery Plugin For Horizontal Text Scrolling - Simple Marquee file 67
8 [JS라이브러리] Responsive & Filterable jQuery Portfolio Gallery Plugin - Elastic Grid file 36
7 [JS라이브러리] Infinite Scroll - Automatically add next page 483
6 [JS라이브러리] Masonry - Cascading grid layout library file 42
5 [JS라이브러리] EasyZoom, jQuery image zoom plugin 93
4 [JS라이브러리] jQuery Lazy – Delayed Image and Background Loader 33
3 [JS라이브러리] jQuery lightGallery 265
2 [JS라이브러리] blueimp Gallery file 484
1 [JS라이브러리] Fotorama file 419
닫기