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. hdu 4714 树形DP

    思路:dp[i][0]表示第i个节点为根的子树变成以i为一头的长链最小的花费,dp[i][0]表示表示第i个节点为根的子树变成i不是头的长链最小花费. 那么动态方程也就不难想了,就是要分几个情况处理, ...

  2. hdu 2489 最小生成树状态压缩枚举

    思路: 直接状态压缩暴力枚举 #include<iostream> #include<algorithm> #include<cstdio> #include< ...

  3. Linux之zsh

    0.安装zsh: sudo apt-get install zsh git wget 1.启用zsh:chsh -s /bin/zsh 2.github: https://github.com/rob ...

  4. @@Error使用简单小结

    使用中经常用到@@Error来判断上一个语句是否执行成功,对此小结一下,可能有些不准确,欢迎指出. 1.1  介绍 SQL SERVER 中@@表示系统全局变量 (1)   返回执行的上一个 Tran ...

  5. arcsde service(esri_sde)服务启动后又停止

    由于最近几天我们公司换了新办公楼,各种服务器得重新配置.当我试图直接将arcsde Service的服务器IP改为现在的地址,就报上面如题的错误. SQL服务器是好的,不用管它,只要确保它是开启的.只 ...

  6. java 集合(list、set、map)的特点

    集合相关的类有一大堆,一般也只用到常用的方法增删改查,而且它它们的方法名也基本一样,所以一直都不知道什么时候用什么集合, 今天趁有空特意从网上整理资料方便日后回忆. 一.List:.有顺序以线性方式存 ...

  7. C# 输出24小时格式时间

    比如   MessageBox.Show(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")); 会输出  2014-4-3 5:08:4[1 ...

  8. jQuery$命名冲突问题解决方法

    也许你在看此文章之前还不知道jquery有一个noConflict()东西了,它就是为了避免与其它js插件碰到相同变量的一个解决方法,利用noConflict()可以把变量存到其它指定的变量中去如,我 ...

  9. echarts标准饼图(一)——基本配置demo

    echarts标准饼图解读共分为四部分, 一.基本配置demo 二.标题(title)配置 三.提示框(tooltip)配置 四.图例(legend)配置 五.系列列表(series )配置 下面是一 ...

  10. 7款超具个性的HTML5播放器

    这篇文章我们要分享一些很有个性的HTML5音乐播放器和视频播放器,它们都具有播放器的大部分功能,并以HTML5和JavaScript实现.这些HTML5播放器有着非常漂亮的外观,很多你都无需自己重新定 ...