HomeGetting StartedDownloadDocumentationBrowse Packages

Introduction#

Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you.

Dependency management#

Composer is not a package manager. Yes, it deals with "packages" or libraries, but it manages them on a per-project basis, installing them in a directory (e.g. vendor) inside your project. By default it will never install anything globally. Thus, it is a dependency manager.

This idea is not new and Composer is strongly inspired by node's npm and ruby's bundler. But there has not been such a tool for PHP.

The problem that Composer solves is this:

a) You have a project that depends on a number of libraries.

b) Some of those libraries depend on other libraries.

c) You declare the things you depend on.

d) Composer finds out which versions of which packages need to be installed, and installs them (meaning it downloads them into your project).

Declaring dependencies#

Let's say you are creating a project, and you need a library that does logging. You decide to usemonolog. In order to add it to your project, all you need to do is create a composer.json file which describes the project's dependencies.

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

We are simply stating that our project requires some monolog/monolog package, any version beginning with 1.2.

System Requirements#

Composer requires PHP 5.3.2+ to run. A few sensitive php settings and compile flags are also required, but the installer will warn you about any incompatibilities.

To install packages from sources instead of simple zip archives, you will need git, svn or hg depending on how the package is version-controlled.

Composer is multi-platform and we strive to make it run equally well on Windows, Linux and OSX.

Installation - *nix#

Downloading the Composer Executable#

Locally#

To actually get Composer, we need to do two things. The first one is installing Composer (again, this means downloading it into your project):

curl -sS https://getcomposer.org/installer | php

Note: If the above fails for some reason, you can download the installer with php instead:

php -r "readfile('https://getcomposer.org/installer');" | php

This will just check a few PHP settings and then download composer.phar to your working directory. This file is the Composer binary. It is a PHAR (PHP archive), which is an archive format for PHP which can be run on the command line, amongst other things.

You can install Composer to a specific directory by using the --install-dir option and providing a target directory (it can be an absolute or relative path):

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

Globally#

You can place this file anywhere you wish. If you put it in your PATH, you can access it globally. On unixy systems you can even make it executable and invoke it without php.

You can run these commands to easily access composer from anywhere on your system:

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

Note: If the above fails due to permissions, run the mv line again with sudo.

Then, just run composer in order to run Composer instead of php composer.phar.

Globally (on OSX via homebrew)#

Composer is part of the homebrew-php project.

brew update
brew tap homebrew/dupes
brew tap homebrew/php
brew install composer

Installation - Windows#

Using the Installer#

This is the easiest way to get Composer set up on your machine.

Download and run Composer-Setup.exe, it will install the latest Composer version and set up your PATH so that you can just call composer from any directory in your command line.

Manual Installation#

Change to a directory on your PATH and run the install snippet to download composer.phar:

C:\Users\username>cd C:\bin
C:\bin>php -r "readfile('https://getcomposer.org/installer');" | php

Note: If the above fails due to readfile, use the http url or enable php_openssl.dll in php.ini

Create a new composer.bat file alongside composer.phar:

C:\bin>echo @php "%~dp0composer.phar" %*>composer.bat

Close your current terminal. Test usage with a new terminal:

C:\Users\username>composer -V
Composer version 27d8904

Using Composer#

We will now use Composer to install the dependencies of the project. If you don't have a composer.json file in the current directory please skip to the Basic Usage chapter.

To resolve and download dependencies, run the install command:

php composer.phar install

If you did a global install and do not have the phar in that directory run this instead:

composer install

Following the example above, this will download monolog into the vendor/monolog/monolog directory.

Autoloading#

Besides downloading the library, Composer also prepares an autoload file that's capable of autoloading all of the classes in any of the libraries that it downloads. To use it, just add the following line to your code's bootstrap process:

require 'vendor/autoload.php';

Woah! Now start using monolog! To keep learning more about Composer, keep reading the "Basic Usage" chapter.

Basic Usage →

Found a typo? Something is wrong in this documentation? Just fork and edit it!

Composer and all content on this site are released under the MIT license.

转自:

https://getcomposer.org/doc/00-intro.md#installation-windows

composer的安装的更多相关文章

  1. composer的安装以及laravel框架的安装(一)

    laravel号称世界上最好的php框架,没有之一,下面介绍它的安装 laravel学习交流qq群:293798134 composer的安装 : php开发者很多,并且在web开发领域占据绝对统治地 ...

  2. 7.Composer的安装和使用

    1.安装Composer: 局部安装 要真正获取 Composer,我们需要做两件事.首先安装 Composer (同样的,这意味着它将下载到你的项目中): curl -sS https://getc ...

  3. XAMPP下的composer的安装

    很多开源软件,都需要通过composer来安装,Composer 是 PHP 的一个依赖管理工具.它允许你申明项目所依赖的代码库,它会在你的项目中为你安装他们. 声明关系 比方说,你正在创建一个项目, ...

  4. 关于在Windows下Composer下载安装Yii2.0

    先是composer的安装,主要有两个方式,一个直接下载安装包安装,Composer-steup.exe文件,第二种直接下载composer.phar文件,用php去运行这个文件可以一样起到作用,之后 ...

  5. PHP Yii2 composer环境安装

    PHP Yii2 composer环境安装 composer 安装 任意目录执行: php -r "copy('https://install.phpcomposer.com/install ...

  6. 一、Composer下载安装

    1.composer下载 英文网站:https://getcomposer.org/ 中文镜像:https://www.phpcomposer.com/ 2.composer安装 • win下安装图文 ...

  7. phpstudy composer 使用安装

    本人是windows 系统 phpstudy 是最新2018版本 以安装laravel框架为例子 一如图一,点击php Composer出现系统指令框,根据指令框路径找到文件 二把红框内文件删除 三在 ...

  8. composer windows安装

    一.下载安装包安装 https://getcomposer.org/download/(由于墙的限制,可能下载可执行文件失败,即使成功,由于网络的原因,安装的时候也可能会失败,所以建议用第二种方法) ...

  9. 优雅得使用composer来安装各种PHP小工具

    Composer对php世界的影响是巨大的,使用composer来代替PEAR一定是大势所趋.当小伙伴们都还沉浸在composer带来的便利的时候,有没有想过如何更好的使用composer呢,网上大部 ...

  10. composer方式安装thinkphp5,安装smarty

    转载地址: https://my.oschina.net/inuxor/blog/750717 composer 是 PHP 用来管理依赖(dependency)关系的工具.你可以在自己的项目中声明所 ...

随机推荐

  1. EasyGUI的安装

    1.下载EasyGUI 在官方网站上下载http://easygui.sourceforge.net/将安装包下载下来,放到桌面上并解压. 2.安装EasyGUI ①在开始菜单的搜索中输入cmd,打开 ...

  2. 编译cordova-android代码

    开发cordova-android的插件得引入cordova的jar包,网上打包好的参差不齐,也不一定是最新版本,下面我们自己打包 cordova的jar包. 1.clone代码 cordova-an ...

  3. 京东2017 C++一面

    一面直接跪,日 1. 重写和重载的区别                            答的一般 2. C++内存分配方式                           不会 3. TCP ...

  4. Web前端学习笔记3

    1.meta标签. 1.1 <meta charset="utf-8"> charset:字符集 1.2 <meta name="keywords&qu ...

  5. 使 div 元素看上去像一个按钮

    使 div 元素看上去像一个按钮 div { appearance:button; -moz-appearance:button; /* Firefox */ -webkit-appearance:b ...

  6. 无需操作系统和虚拟机,直接运行Python代码

    Josh Triplett以一个“笑点”开始了他在PyCon 2015上的演讲:移植Python使其无需操作系统运行:他和他的英特尔同事让解释器能够在GRUB引导程序.BIOS或EFI系统上运行.连演 ...

  7. oracle生成.net的guid方法;

    最近在做一个T1的.NET项目,数据库oracle的时候,遇到一个问题..NET里面的某个数据库表类的某个字段是guid类型.但是用oracle生成的guid.跟.NET的guid 无法识别.导致报错 ...

  8. 标识映射(Identify Map)

    通过在Map中保存每个已加载过的对象,确保每个对象只加载一次. 当要访问对象时,首先检查标识映射,看需要的对象是否已经存在其中. 使用Identify来确保不重复加载相同的数据,不仅有助于保证正确性( ...

  9. JAVA:二进制(原码 反码 补码),位运算,移位运算,约瑟夫问题(5)

    一.二进制,位运算,移位运算 1.二进制 对于原码, 反码, 补码而言, 需要注意以下几点: (1).Java中没有无符号数, 换言之, Java中的数都是有符号的; (2).二进制的最高位是符号位, ...

  10. CentOS 7.2 无法生成 coredump文件

    CentOS版本 cat /etc/centos-release  CentOS Linux release 7.2.1511 (Core) 设置ulimit -c ulimited 依旧无法生成co ...