如何在没有Composer的情况下安装Composer PHP软件包?

时间:2023-01-12 19:57:19

I'm trying to install the Coinbase PHP API but it requires Composer:

我正在尝试安装Coinbase PHP API,但它需要Composer:

https://github.com/coinbase/coinbase-php

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.

我正在寻找一个通用的PHP解决方案(可能是一个函数)让我直接将编写器包安装到我的服务器上,而不必使用Composer。

I think the developers of Composer believe they are helping people, but actually there are thousands of beginner developers that are being locked out of learning web development by the 'Composer barrier'.

我认为Composer的开发人员相信他们正在帮助人们,但实际上有成千上万的初学者开发者被“作曲家障碍”锁定在学习Web开发之外。

It would really help if there was a flexible solution or some approach where we could install without Composer? How can I do this?

如果有灵活的解决方案或某种方法可以在没有Composer的情况下安装,那真的会有所帮助吗?我怎样才能做到这一点?

Please don't respond with some sarcastic comment. There are people that don't want to use Composer and I don't see why we should be herded into a specific third-party software in order to do web development.

请不要回应一些讽刺的评论。有些人不想使用Composer,我不明白为什么我们应该成为特定的第三方软件才能进行Web开发。

5 个解决方案

#1


15  

The composer.json file lists the dependencies. In your example:

composer.json文件列出了依赖项。在你的例子中:

"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.

然后,您必须在packagist站点中找到相应的包。对每个依赖项重复相同的过程:在相应的composer.json文件中查找其他依赖项并再次搜索。

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.:

当您最终获得所需包的完整列表时,您只需要逐个安装它们。在大多数情况下,只需将文件放在项目目录中的某个位置即可。但您还必须确保PHP可以找到所需的类。由于您没有使用Composer的自动加载器,因此需要将它们添加到您自己的自定义自动加载器中。你可以从各自的composer.json文件中找出信息,例如:

"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.

如果您不使用类自动加载器,则需要确定各个require_once语句。您可能需要大量的试验和错误,因为大多数图书馆作者都不会关心这一点。

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具有适用于Windows的官方GUI安装程序以及适用于所有平台的复制和粘贴命令行安装过程。
  • Composer can be run locally and its output just uploaded elsewhere. You don't need SSH in your shared hosting.
  • Composer可以在本地运行,其输出只是在其他地方上传。您的共享主机中不需要SSH。
  • The command needed to install a library can be copied and pasted from the package web site—even if the package maintainer didn't care to document it, packagist.org generates it by default.
  • 安装库所需的命令可以从包网站复制和粘贴 - 即使软件包维护者不关心它,packagist.org默认生成它。

Composer is not perfect and it doesn't suit all use cases but, when it comes to installing a library that relies on it, it's undoubtedly the best alternative and it's a fairly decent one.

Composer并不完美,并不适合所有用例,但是,当涉及到安装依赖它的库时,它无疑是最好的选择,而且它是一个相当不错的选择。


I've checked other answers that came after mine. They mostly fall in two categories:

我已经检查了我之后的其他答案。它们大多分为两类:

  1. Install a library and write a custom download script with it
  2. 安装库并使用它编写自定义下载脚本
  3. Use an online web based interface for Composer
  4. 使用Composer的在线基于Web的界面

Unless I'm missing something, none of them address the complaints expressed by the OP:

除非我遗漏了什么,否则他们都没有解决OP所表达的抱怨:

  • Learning curve
  • 学习曲线
  • Use of third-party software
  • 使用第三方软件
  • Possibility to develop right on the server (using SSH, I presume)
  • 可以在服务器上开发(使用SSH,我猜)
  • Potentially deep dependency tree
  • 潜在的深度依赖树

#2


30  

You can try https://php-download.com/ which can help you download all dependency most of the time along with vendor folder. It promises composer not required. Tried it myself. It finds and creates all required folders and zips it for download. Works perfectly !!

您可以尝试https://php-download.com/,它可以帮助您在大多数情况下下载所有依赖项以及供应商文件夹。它承诺作曲家不需要。自己试了一下。它查找并创建所有必需的文件夹并将其拉下以供下载。完美的工作!

#3


2  

I had to do this for an FTP server I didn't have SSH access to. The site listed in here worked, then I realized you can just do a composer install on your own server (using your target's PHP version), then copy all the files over.

我不得不为没有SSH访问权限的FTP服务器执行此操作。这里列出的网站工作,然后我意识到你可以在你自己的服务器上安装一个作曲家(使用你的目标的PHP版本),然后复制所有的文件。

#4


2  

This is not the ultimate solution but for me it was a big help for most of the cases: https://github.com/Wilkins/composer-file-loader

这不是最终的解决方案,但对我来说这对大多数情况来说是一个很大的帮助:https://github.com/Wilkins/composer-file-loader

Allow you to load composer.json file just as composer would do it. This allow you to load composer.json file without composer (so theorically PHP 5.2 is enough)

允许您像composer一样加载composer.json文件。这允许你加载没有composer的composer.json文件(所以理论上PHP 5.2就足够了)

I know the question is old but I hope it will help someone.

我知道这个问题已经过时了,但我希望它会对某人有所帮助。

#5


0  

I'm using shared hosting for a website and can't execute commands there. Aside from running composer via php script request that I request via browser, I usually use this workflow:

我正在使用网站的共享主机,并且无法在那里执行命令。除了通过浏览器请求的php脚本请求运行composer之外,我通常使用这个工作流程:

  • Make sure you have php installed locally.
  • 确保你在本地安装了php。
  • Make directory on desktop.
  • 在桌面上创建目录。
  • download composer.phar from https://getcomposer.org/download/ (under header *Manual Download) and place it in the directory.
  • 从https://getcomposer.org/download/下载composer.phar(在header * Manual Download下)并将其放在目录中。
  • make a file composer.json paste in it the following contents

    make文件composer.json将以下内容粘贴到其中

     {
         "require": {
             "coinbase/coinbase": "~2.0"
         }
     }
    
  • Browse to the directory with the shell of your choice(bash, git-bash, cmd, windows bash)

    浏览到您选择的shell目录(bash,git-bash,cmd,windows bash)

  • type php composer.phar update 如何在没有Composer的情况下安装Composer PHP软件包?
  • 输入php composer.phar update
  • Upload the vendor directory to your webserver via ftp or whatever mechanic you use.
  • 通过ftp或您使用的任何技工将供应商目录上传到您的网络服务器。
  • include in your php project where you load your libraries(modify path to where you uploaded the vendor dir so it will include that autoload file)

    包含在您加载库的php项目中(修改上传供应商目录的路径,以便包含该自动加载文件)

    require_once('vendor/autoload.php');
    

This way you get the benefit of dependency management and you don't have to include manually all the gazillion of files and download all the dependencies manually, and updating them is just as easy as typing php composer.phar update and then replacing the vendor dir on your server with the new one.

通过这种方式,您可以获得依赖关系管理的好处,并且您不必手动包含所有大量文件并手动下载所有依赖项,并且更新它们就像输入php composer.phar update然后替换vendor dir一样简单在您的服务器上使用新的。

#1


15  

The composer.json file lists the dependencies. In your example:

composer.json文件列出了依赖项。在你的例子中:

"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.

然后,您必须在packagist站点中找到相应的包。对每个依赖项重复相同的过程:在相应的composer.json文件中查找其他依赖项并再次搜索。

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.:

当您最终获得所需包的完整列表时,您只需要逐个安装它们。在大多数情况下,只需将文件放在项目目录中的某个位置即可。但您还必须确保PHP可以找到所需的类。由于您没有使用Composer的自动加载器,因此需要将它们添加到您自己的自定义自动加载器中。你可以从各自的composer.json文件中找出信息,例如:

"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.

如果您不使用类自动加载器,则需要确定各个require_once语句。您可能需要大量的试验和错误,因为大多数图书馆作者都不会关心这一点。

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具有适用于Windows的官方GUI安装程序以及适用于所有平台的复制和粘贴命令行安装过程。
  • Composer can be run locally and its output just uploaded elsewhere. You don't need SSH in your shared hosting.
  • Composer可以在本地运行,其输出只是在其他地方上传。您的共享主机中不需要SSH。
  • The command needed to install a library can be copied and pasted from the package web site—even if the package maintainer didn't care to document it, packagist.org generates it by default.
  • 安装库所需的命令可以从包网站复制和粘贴 - 即使软件包维护者不关心它,packagist.org默认生成它。

Composer is not perfect and it doesn't suit all use cases but, when it comes to installing a library that relies on it, it's undoubtedly the best alternative and it's a fairly decent one.

Composer并不完美,并不适合所有用例,但是,当涉及到安装依赖它的库时,它无疑是最好的选择,而且它是一个相当不错的选择。


I've checked other answers that came after mine. They mostly fall in two categories:

我已经检查了我之后的其他答案。它们大多分为两类:

  1. Install a library and write a custom download script with it
  2. 安装库并使用它编写自定义下载脚本
  3. Use an online web based interface for Composer
  4. 使用Composer的在线基于Web的界面

Unless I'm missing something, none of them address the complaints expressed by the OP:

除非我遗漏了什么,否则他们都没有解决OP所表达的抱怨:

  • Learning curve
  • 学习曲线
  • Use of third-party software
  • 使用第三方软件
  • Possibility to develop right on the server (using SSH, I presume)
  • 可以在服务器上开发(使用SSH,我猜)
  • Potentially deep dependency tree
  • 潜在的深度依赖树

#2


30  

You can try https://php-download.com/ which can help you download all dependency most of the time along with vendor folder. It promises composer not required. Tried it myself. It finds and creates all required folders and zips it for download. Works perfectly !!

您可以尝试https://php-download.com/,它可以帮助您在大多数情况下下载所有依赖项以及供应商文件夹。它承诺作曲家不需要。自己试了一下。它查找并创建所有必需的文件夹并将其拉下以供下载。完美的工作!

#3


2  

I had to do this for an FTP server I didn't have SSH access to. The site listed in here worked, then I realized you can just do a composer install on your own server (using your target's PHP version), then copy all the files over.

我不得不为没有SSH访问权限的FTP服务器执行此操作。这里列出的网站工作,然后我意识到你可以在你自己的服务器上安装一个作曲家(使用你的目标的PHP版本),然后复制所有的文件。

#4


2  

This is not the ultimate solution but for me it was a big help for most of the cases: https://github.com/Wilkins/composer-file-loader

这不是最终的解决方案,但对我来说这对大多数情况来说是一个很大的帮助:https://github.com/Wilkins/composer-file-loader

Allow you to load composer.json file just as composer would do it. This allow you to load composer.json file without composer (so theorically PHP 5.2 is enough)

允许您像composer一样加载composer.json文件。这允许你加载没有composer的composer.json文件(所以理论上PHP 5.2就足够了)

I know the question is old but I hope it will help someone.

我知道这个问题已经过时了,但我希望它会对某人有所帮助。

#5


0  

I'm using shared hosting for a website and can't execute commands there. Aside from running composer via php script request that I request via browser, I usually use this workflow:

我正在使用网站的共享主机,并且无法在那里执行命令。除了通过浏览器请求的php脚本请求运行composer之外,我通常使用这个工作流程:

  • Make sure you have php installed locally.
  • 确保你在本地安装了php。
  • Make directory on desktop.
  • 在桌面上创建目录。
  • download composer.phar from https://getcomposer.org/download/ (under header *Manual Download) and place it in the directory.
  • 从https://getcomposer.org/download/下载composer.phar(在header * Manual Download下)并将其放在目录中。
  • make a file composer.json paste in it the following contents

    make文件composer.json将以下内容粘贴到其中

     {
         "require": {
             "coinbase/coinbase": "~2.0"
         }
     }
    
  • Browse to the directory with the shell of your choice(bash, git-bash, cmd, windows bash)

    浏览到您选择的shell目录(bash,git-bash,cmd,windows bash)

  • type php composer.phar update 如何在没有Composer的情况下安装Composer PHP软件包?
  • 输入php composer.phar update
  • Upload the vendor directory to your webserver via ftp or whatever mechanic you use.
  • 通过ftp或您使用的任何技工将供应商目录上传到您的网络服务器。
  • include in your php project where you load your libraries(modify path to where you uploaded the vendor dir so it will include that autoload file)

    包含在您加载库的php项目中(修改上传供应商目录的路径,以便包含该自动加载文件)

    require_once('vendor/autoload.php');
    

This way you get the benefit of dependency management and you don't have to include manually all the gazillion of files and download all the dependencies manually, and updating them is just as easy as typing php composer.phar update and then replacing the vendor dir on your server with the new one.

通过这种方式,您可以获得依赖关系管理的好处,并且您不必手动包含所有大量文件并手动下载所有依赖项,并且更新它们就像输入php composer.phar update然后替换vendor dir一样简单在您的服务器上使用新的。