最新消息:觉得本站不错的话 记得收藏哦 博客内某些功能仅供测试 讨论群:135931704 快养不起小站了 各位有闲钱就打赏下把 My Email weicots#gmail.com Please replace # with @

Composer Centos 下安装

FEE ajiang-tuzi 4606浏览

环境
操作系统CentOS 7
PHP集成开发环境:LNMP
Composer 介绍
Composer 是 PHP 的一个依赖管理工具。它允许你申明项目所依赖的代码库,它会在你的项目中为你安装他们。Composer 不是一个包管理器。它在每个项目的基础上进行管理,在你项目的某个目录中进行安装。默认情况下它不会在全局安装任何东西。因此,这仅仅是一个依赖管理。

Composer 将这样为你解决问题:
a) 你有一个项目依赖于若干个库。
b) 其中一些库依赖于其他库。
c) 你声明你所依赖的东西。
d) Composer 会找出哪个版本的包需要安装,并安装它们(将它们下载到你的项目中)。
Composer 是多平台的,我们努力使它在 Windows 、 Linux 以及 OSX 平台上运行的同样出色。
安装Composer
1、将composer.phar下载到项目中
使用curl -sS https://getcomposer.org/installer | php[/php]下载Composer 的二进制文件,是一个 PHAR 包(PHP 的归档)
2、可以通过 –install-dir 选项指定 Composer 的安装目录(它可以是一个绝对或相对路径):

curl -sS https://getcomposer.org/installer | php -- --install-dir=lumen

3、如果把composer.phar放在系统的 PATH 目录中,就能在全局访问composer.phar。 在类Unix系统中,你甚至可以在使用时不加 php 前缀。可以执行这些命令让 composer 在你的系统中进行全局调用:

#mv composer.phar /usr/local/bin/composer

现在只需要运行 composer 命令就可以使用 Composer 而不需要输入 php composer.phar。
4、检查 Composer 是否正常工作,只需要通过 php 来执行 PHAR:php composer.phar这将返回给你一个可执行的命令列表。
使用 Composer
要在项目中使用 Composer,只需要一个 composer.json 文件。该文件包含了项目的依赖和其它的一些元数据。现在使用 Composer 来安装项目的依赖。
1、创建 composer.json 文件
在当前目录下创建 composer.json 文件,在 composer.json 文件中指定 require key 的值。简单的告诉 Composer 你的项目需要依赖哪些包。
例如:

{    "require": {        "monolog/monolog": "1.0.*"    } }

可以看到, require 需要一个 包名称 monolog/monolog映射到 包版本 1.0.*的对象。包名称由供应商名称和其项目名称构成。
2、安装依赖包
执行 install 命令获取定义的依赖到本地项目:
php composer.phar install
如果你进行了全局安装,并且没有 phar 文件在当前目录,使用下面的命令代替:

composer install

这将会找到 monolog/monolog 的最新版本,并将它下载到 vendor 目录。 这是一个惯例把第三方的代码到一个指定的目录 vendor。如果是 monolog 将会创建 vendor/monolog/monolog 目录。
注意: install 命令将创建一个 composer.lock 文件到你项目的根目录中。

[root@ajiang-tuzi wwwroot]# composer
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 1.0-dev (d6ae9a0529e1f39c4c7f9b2f29fff019d79cd1fb) 2015-12-22 20:44:41

Usage:
  command [options] [arguments]

Options:
  -h, --help                     Display this help message
  -q, --quiet                    Do not output any message
  -V, --version                  Display this application version
      --ansi                     Force ANSI output
      --no-ansi                  Disable ANSI output
  -n, --no-interaction           Do not ask any interactive question
      --profile                  Display timing and memory usage information
  -d, --working-dir=WORKING-DIR  If specified, use the given directory as working directory.
  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  about           Short information about Composer
  archive         Create an archive of this composer package
  browse          Opens the package's repository URL or homepage in your browser.
  clear-cache     Clears composer's internal package cache.
  clearcache      Clears composer's internal package cache.
  config          Set config options
  create-project  Create new project from a package into given directory.
  depends         Shows which packages depend on the given package
  diagnose        Diagnoses the system to identify common errors.
  dump-autoload   Dumps the autoloader
  dumpautoload    Dumps the autoloader
  global          Allows running commands in the global composer dir ($COMPOSER_HOME).
  help            Displays help for a command
  home            Opens the package's repository URL or homepage in your browser.
  info            Show information about packages
  init            Creates a basic composer.json file in current directory.
  install         Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.
  licenses        Show information about licenses of dependencies
  list            Lists commands
  remove          Removes a package from the require or require-dev
  require         Adds required packages to your composer.json and installs them
  run-script      Run the scripts defined in composer.json.
  search          Search for packages
  self-update     Updates composer.phar to the latest version.
  selfupdate      Updates composer.phar to the latest version.
  show            Show information about packages
  status          Show a list of locally modified packages
  suggests        Show package suggestions
  update          Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file.
  validate        Validates a composer.json and composer.lock

备注及引用
本文 整理自互联网 仅供学习和交流所用

转载请注明:(●--●) Hello.My Weicot » Composer Centos 下安装

蜀ICP备15020253号-1