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. org.springframework.dao.InvalidDataAccessApiUsageException:The given object has a null identifi的解决方案

    异常信息: org.springframework.dao.InvalidDataAccessApiUsageException: The given object has a null identi ...

  2. 关于cornerstone无法上传library文件的问题

    在CornerStone中先选中左边的项目: 然后在菜单栏里面选择View->ShowIgnoreItems, 再选择项目中的library文件,点击Add按钮即可上传到服务器:

  3. 代码创建FlexibleSpaceBarButton(弹性空白)

    //1.创建toolbar左边的按钮,调用initWithTitle方法进行初始化 // UIBarButtonItem *extend = [[UIBarButtonItemalloc]initWi ...

  4. Google Chrome 55 Released – Install on RHEL/CentOS 7/6 and Fedora 25-20

    Google Chrome is a freeware web browser developed by Google Inc. Google Chrome team proudly announce ...

  5. Unity之读取本地图片

    1.下载Opencv for unity. 2.把OpenCVForUnity下的StreamingAssets拖到Assets下. 3.点击Tools->opencv for unity-&g ...

  6. PHP计算中英混输字符串长度

    最近做项目中碰到需要post value length check的这么一个情况 有这么一个需求, 需要backend来处理post过来的中英混输的数据. 对其限制的规则是中文10个字符, 英文20个 ...

  7. linux /etc/sysctl.conf 禁止别人ping自己

    vi /etc/sysctl.conf如果希望屏蔽别人 ping 你的主机,则加入以下代码:# Disable ping requestsnet.ipv4.icmp_echo_ignore_all = ...

  8. z-index无效

    1.要想给元素设置z-index样式,必须先让它变成定位元素,说的明白一点,就是要给元素设置一个postion:relative(定位元素:position属性值设置除默认值static以外的元素,包 ...

  9. Chrome JS内存泄漏排查方法(Chrome Profiles)

     原文网址:http://blog.csdn.net/kaitiren/article/details/19974269 JS内存泄漏排查方法(Chrome Profiles)   Google Ch ...

  10. 使用Eclipse maven构建springmvc项目

    Eclipse maven构建springmvc项目 Listener 监听器 架构 使用Log4J监控系统日志邮件警报 2014-12-16 13:09:16 控制器在完成逻辑处理后,通常会产生一些 ...