How to install Composer PHP package without Composer?
P粉278379495
P粉278379495 2023-08-22 12:37:12
0
2
481
<p>I'm trying to install the Coinbase PHP API but it requires Composer: </p> <p>https://github.com/coinbase/coinbase-php</p> <p>I'm looking for a general PHP solution (perhaps a function) that would allow me to install Composer packages directly on the server without having to use Composer. </p> <p>I think the developers of Composer think they are helping people, but there are actually thousands of beginner developers who are unable to learn web development because of "Composer Barrier". </p> <p>If there is a flexible solution or some way to install without Composer? what should I do? </p> <p><strong>Please do not reply to sarcastic comments</strong>. Some people don't want to use Composer, and I don't see why we should be forced to use specific third-party software for web development. </p>
P粉278379495
P粉278379495

reply all(2)
P粉268654873

You can try https://php-download.com/, it can help you download all dependencies most of the time, along with vendor folder. It promises that composer is not required. I tried it myself. It will find and create all required folders and zip them for download. Works perfectly! !

P粉403804844

In your example, the composer.json file lists the dependencies.

"require": {
    "php": ">=5.5.0",
    "guzzlehttp/guzzle": "^6.0",
    "psr/http-message": "^1.0",
    "psr/log": "^1.0"
},

Then, you need to find the corresponding package on the packagist website. For each dependency, repeat the same process: find the other dependencies in their corresponding composer.json files and search again.

When you finally have the complete list of required packages, you just need to install them one by one. In most cases, simply placing the file somewhere in the project directory will suffice. But you also have to make sure PHP can find the required classes. Since you're not using Composer's autoloader, you'll need to add them to your own custom autoloader. You can get the information from the corresponding composer.json file, for example:

"autoload": {
    "psr-4": { "Coinbase\Wallet\": "src/" }
},

If you are not using a class autoloader, you need to find the individual require_once statements. Since most library authors won't care about this, you may need to do a lot of trial and error.

Also, in case there is any confusion on this matter:

  • Composer has an official Windows graphical interface installer and a copy-paste command line installation process for all platforms.
  • Composer can be run locally and its output can be uploaded elsewhere. You don't need to use SSH on shared hosting.
  • The command required to install the library can be copy-pasted from the package's website, and packagist.org will generate it by default even if the maintainer of the package is unwilling to document it.

Composer is not perfect, nor is it suitable for all use cases, but when it comes to installing libraries that depend on it, it is undoubtedly the best choice, and a pretty good one at that.


I looked at the other answers after my answer. They are mainly divided into two categories:

  1. Install the library and write a custom download script
  2. Using the web-based Composer online interface

Unless I'm missing something, none of them address the question raised by the OP:

  • learning curve
  • Use third-party software
  • Possibly developing on the server (using SSH, I presume)
  • Potential deep dependency tree
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!