php 我把 composer.json 放在哪里

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22155554/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:42:03  来源:igfitidea点击:

where do I put composer.json

phpcomposer-php

提问by Angad Dubey

I have installed composer.

我已经安装了作曲家。

My project dir tree looks something like this

我的项目目录树看起来像这样

/home/myproject/public_html/myproject.com

I initially installed it in:

我最初将它安装在:

/home/myproject/public_html/myproject.com/bin/composer/

But later moved it to:

但后来将其移至:

/home/myproject/usr/local/bin/composer

Questions:

问题:

  1. Where to I create composer.json ?
  2. In the official docs they mention that in order to install new packages I need to write a require key in the json format in that file, does this mean that I dont have to upload the package through ftp?
  3. The docs further say that I can simply install dependencies like ths:

    php composer.phar install

  1. 我在哪里创建 composer.json ?
  2. 在官方文档中,他们提到为了安装新软件包,我需要在该文件中以 json 格式编写一个 require 密钥,这是否意味着我不必通过 ftp 上传软件包?
  3. 文档进一步说我可以简单地安装像这样的依赖项:

    php composer.phar 安装

I dont understand the workflow of this process (im fairly new).. what exactly do I need to do to get some packages going (like Respect)

我不明白这个过程的工作流程(我还很新)。我到底需要做什么才能让一些包运行(比如尊重

回答by BillyBigPotatoes

Composer has 2 basic elements for you to consider:

Composer 有 2 个基本要素供您考虑:

  1. The composer.php file itself - this can be located anywhere on your system - usually it is convenient to have it in you search path so you can invoke it by name (no path) from the command line.

  2. Composer.json - this file is the configuration for your project. This is usually best located at the top level of your project. Ideally this is a directory outside the scope of your web server - so that it will never be exposed or served.

  1. composer.php 文件本身——它可以位于你系统的任何地方——通常把它放在你的搜索路径中是很方便的,这样你就可以从命令行按名称(无路径)调用它。

  2. Composer.json - 此文件是您项目的配置。这通常最好位于项目的顶层。理想情况下,这是一个在您的 Web 服务器范围之外的目录 - 这样它就永远不会被公开或提供。

Symfony2 has some great documentation and examples of composer in use.

Symfony2 有一些很棒的文档和使用中的作曲家示例。

Also be aware that some packages you reference via composer will themselves have composer files - to ensure they match your required dependancies - and they may also have their own dependancies that need to be considered.

另请注意,您通过 Composer 引用的某些包本身将具有 Composer 文件 - 以确保它们与您所需的依赖项匹配 - 而且它们可能也有自己需要考虑的依赖项。

I would install composer.json in the following

我会在下面安装 composer.json

/home/myproject/composer.json

It would be out of scope of the web server and could be used to manage many assets e.g.

它超出了 Web 服务器的范围,可用于管理许多资产,例如

  public_html/
  libs/
  config/
  docs/
  vendor/

回答by Rahil Wazir

Where to I create composer.json ?

我在哪里创建 composer.json ?

You should create composer.jsonto your project root like /home/myproject/public_html/myproject.com/composer.json. If all files of your application live inside your myproject.comfolder.

您应该composer.json/home/myproject/public_html/myproject.com/composer.json. 如果您的应用程序的所有文件都位于您的myproject.com文件夹中。

In the official docs they mention that in order to install new packages I need to write a require key in the json format in that file, does this mean that I dont have to upload the package through ftp?

在官方文档中,他们提到为了安装新软件包,我需要在该文件中以 json 格式编写一个 require 密钥,这是否意味着我不必通过 ftp 上传软件包?

Yes as long as you're not in shared hosting because most of them don't allow CLI (SSH).

是的,只要您不在共享主机中,因为它们中的大多数不允许 CLI (SSH)。

The docs further say that I can simply install dependencies like this

文档进一步说我可以简单地安装这样的依赖项

php composer.phar install

Yes you can simple type the above command and composer.json will install the latest version of your package.

是的,您可以简单地输入上述命令,composer.json 将安装您的软件包的最新版本。

Composer.json(Respect Package)

Composer.json(尊重包)

{
    "require": {
        "respect/validation": "dev-master"
    }
}

Now run composer installwill install the require package.

现在运行composer install将安装需要的包。

For further packages

更多套餐

{
    "require": {
        "respect/validation": "dev-master",
        "doctrine/orm": "2.*"
    }
}

Now run update composer updateit will download the doctrine/ormas well.

现在运行更新composer update它也会下载doctrine/orm