简体   繁体   English

是否已独立安装Composer模块OS?

[英]Are installed Composer modules OS independent?

I know the scenario below is far from modern best practices but let's give it a go. 我知道以下情况与现代最佳实践相去甚远,但让我们尝试一下。

Let's assume that: 假设:

  1. you have development environment and server with the same PHP version but different OSes. 您拥有具有相同PHP版本但操作系统不同的开发环境和服务器。
  2. you want/must deploy your vendors folder to the server as is. 您想要/必须将供应商文件夹原样部署到服务器。

How probable is it that: some packages will fail to work because of OS switching AND the failure could be avoided if they were installed from composer json file on the server (ie they're not completely platform dependent)? 它的可能性有多大:某些软件包会由于操作系统切换而无法工作,并且如果从服务器上的composer json文件安装了这些软件包,则可以避免失败(即它们并不完全依赖于平台)?

I know from this question that absolute paths set during installation may be a problem. 我从这个问题知道在安装过程中设置的绝对路径可能是一个问题。 Are there there other possible issues? 还有其他可能的问题吗?

The probability is pretty high because composer will work differently depending on the environment settings. 可能性很高,因为作曲家会根据环境设置而有所不同。

The simple example of this would be https://getcomposer.org/doc/articles/scripts.md 一个简单的例子是https://getcomposer.org/doc/articles/scripts.md

which can run custom logic dependent on the installed components and prepare something only if the host OS has something available - which - has nothing to do with composer.lock 它可以运行依赖于已安装组件的自定义逻辑,并且仅在主机操作系统具有可用的东西时才准备一些东西-该东西与composer.lock无关

The core problem is that you want to reuse vendor folder. 核心问题是您想重用供应商文件夹。 Composer is not made to work this way and this is why vendor is often mentioned in .gitignore file. 不能使Composer如此工作,这就是为什么.gitignore文件中经常提到vendor原因。 composer will behave differently per environment and its result should not be copied over. 作曲家的行为将因环境而异,其结果不应复制。 If you want to make behaviour consistent between OS-es, use Docker or vagrant to stabilize the application and its environment. 如果要使OS-es之间的行为保持一致,请使用Docker或vagrant稳定应用程序及其环境。

They should be independent from OS, as long you commit composer.lock into your project. 只要您将composer.lock提交到项目中,它们就应该独立于OS。 The point of composer.lock is to install the same packages by composer install independent from OS, and Composer itself does not use any absolute paths (by default). composer.lock的要点是通过独立于OS的composer install相同的软件包,并且Composer本身不使用任何绝对路径(默认情况下)。 In fact Composer maintainers discourage using it in production and many issues have been closed with "Composer is not a deployment tool" as a reason. 实际上,Composer维护人员不鼓励在生产中使用它,并且由于“ Composer不是部署工具”,已经解决了许多问题。 So by design you should be able to move installations between environments and on every system you will get the same packages installed by composer install . 因此,通过设计,您应该能够在环境之间移动安装,并且在每个系统上,您将获得由composer install的相同软件包。

The only problems may come from scripts and/or plugins , which may do some things that are not portable and you need to run it on target installation. 唯一的问题可能来自脚本和/或插件 ,它们可能会执行某些不可移植的操作,因此您需要在目标安装上运行它。


So in short: Yes, installations are independent from OS (unless you do something, that will change that). 简而言之:是的,安装独立于操作系统(除非您做某事,否则它将改变这一点)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM