I'm trying to install the Coinbase PHP API but it requires Composer:
https://github.com/coinbase/coinbase-php
I'm looking for a universal PHP solution (perhaps a function) to let me install composer packages directly onto my server, without having to use Composer.
ベストアンサー1
The composer.json
file lists the dependencies. In your example:
"require": {
"php": ">=5.5.0",
"guzzlehttp/guzzle": "^6.0",
"psr/http-message": "^1.0",
"psr/log": "^1.0"
},
You must then find the corresponding packages in the packagist site. Repeat the same process for each dependency: find additional dependencies in their corresponding composer.json
files and search again.
When you finally have a complete list of the required packages, you only need to install them all one by one. For the most part, it's just a matter of dropping the files somewhere in your project directory. But you must also ensure that PHP can find the needed classes. Since you aren't using Composer's auto-loader, you need to add them to your own custom autoloader. You can figure out the information from the respective composer.json
files, e.g.:
"autoload": {
"psr-4": { "Coinbase\\Wallet\\": "src/" }
},
If you don't use a class auto-loader you'll need to figure out the individual require_once
statements. You'll probably need a lot of trial and error because most library authors won't care documenting that.
Also, and just in case there's confusion about this:
- Composer has an official GUI installer for Windows and a copy and paste command-line installation procedure for all platforms.
- Composer can be run locally and its output just uploaded elsewhere. You don't need SSH in your shared hosting.
- ライブラリをインストールするために必要なコマンドは、パッケージの Web サイトからコピーして貼り付けることができます。パッケージのメンテナーがそれを文書化していなくても、packagist.org はデフォルトでそれを生成します。
Composer は完璧ではなく、すべてのユースケースに適しているわけではありませんが、それに依存するライブラリをインストールする場合、間違いなく最良の代替手段であり、かなり優れたものです。
私の後に寄せられた他の回答も確認してみました。それらは主に 2 つのカテゴリに分類されます。
- ライブラリをインストールし、それを使ってカスタムダウンロードスクリプトを作成します。
- Composerのオンラインウェブベースのインターフェースを使用する
私が何かを見落としていない限り、それらのどれも OP が表明した苦情には対応していません。
- 学習曲線
- サードパーティソフトウェアの使用
- サーバー上で直接開発できる可能性(SSH を使用)
- 潜在的に深い依存関係ツリー