composer的安装
HomeGetting StartedDownloadDocumentationBrowse Packages
- Dependency management
- Declaring dependencies
- System Requirements
- Installation - *nix
- Installation - Windows
- Using Composer
- Autoloading
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
phpinstead:
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
mvline 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
httpurl 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.
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的安装的更多相关文章
- composer的安装以及laravel框架的安装(一)
laravel号称世界上最好的php框架,没有之一,下面介绍它的安装 laravel学习交流qq群:293798134 composer的安装 : php开发者很多,并且在web开发领域占据绝对统治地 ...
- 7.Composer的安装和使用
1.安装Composer: 局部安装 要真正获取 Composer,我们需要做两件事.首先安装 Composer (同样的,这意味着它将下载到你的项目中): curl -sS https://getc ...
- XAMPP下的composer的安装
很多开源软件,都需要通过composer来安装,Composer 是 PHP 的一个依赖管理工具.它允许你申明项目所依赖的代码库,它会在你的项目中为你安装他们. 声明关系 比方说,你正在创建一个项目, ...
- 关于在Windows下Composer下载安装Yii2.0
先是composer的安装,主要有两个方式,一个直接下载安装包安装,Composer-steup.exe文件,第二种直接下载composer.phar文件,用php去运行这个文件可以一样起到作用,之后 ...
- PHP Yii2 composer环境安装
PHP Yii2 composer环境安装 composer 安装 任意目录执行: php -r "copy('https://install.phpcomposer.com/install ...
- 一、Composer下载安装
1.composer下载 英文网站:https://getcomposer.org/ 中文镜像:https://www.phpcomposer.com/ 2.composer安装 • win下安装图文 ...
- phpstudy composer 使用安装
本人是windows 系统 phpstudy 是最新2018版本 以安装laravel框架为例子 一如图一,点击php Composer出现系统指令框,根据指令框路径找到文件 二把红框内文件删除 三在 ...
- composer windows安装
一.下载安装包安装 https://getcomposer.org/download/(由于墙的限制,可能下载可执行文件失败,即使成功,由于网络的原因,安装的时候也可能会失败,所以建议用第二种方法) ...
- 优雅得使用composer来安装各种PHP小工具
Composer对php世界的影响是巨大的,使用composer来代替PEAR一定是大势所趋.当小伙伴们都还沉浸在composer带来的便利的时候,有没有想过如何更好的使用composer呢,网上大部 ...
- composer方式安装thinkphp5,安装smarty
转载地址: https://my.oschina.net/inuxor/blog/750717 composer 是 PHP 用来管理依赖(dependency)关系的工具.你可以在自己的项目中声明所 ...
随机推荐
- state/ui-router
state/ui-router 一个状态对应于一个页面位置 通过定义controller.template和view等属性,来定义指定位置的用户界面和界面行为 通过嵌套的方式来解决页面中的一些重复出现 ...
- 数据库知识(主要基于Oracle,Sql可参考)
1.关于Union的知识 select 11 from dual union select 11 from dual 和 select 11 from dual union all select 11 ...
- canvas-js贝塞尔曲线代码在线生成工具
详细内容请点击 canvas贝塞尔曲线代码在线生成工具 可以快速生成二次.三次贝塞尔曲线的源码生成器,方便经常使用到canvas画图的同学使用,可以直接预览效果随意画出自己想要的图像. 生成源码效果预 ...
- [CAMCOCO][C#]我的系统架构.服务器端.(三)----Model层
我估计一片帖子写不完这个,慢慢来吧... 先上个图,按照图来说明应该容易说清楚一些. 在Model Core核心代码中,老胡创建了一个类 CAMCOCO.Model.Core,要求今后在Model L ...
- PHP中变量,常量,超级全局变量小结
//一般来说,变量在函数无法在函数体中无法访问,但是常量可以.//超级全局变量确实可以的,地址栏上的参数/*$GLOBALS //变量注册的信息$_GET //地址栏参数$_POST ...
- web.config配置aspx页面默认引用的namespace
如果我们在aspx页面上使用<%%>的方式使用某些类的时候很多都没办法直接使用,我们必须要在页面上引用命名空间, 如:如果我们要使用DataTable类的时候,我们必须先使用<%@ ...
- SQLite&&SharedPreferences&&IO读写Sdcard学习笔记
SQLite 轻量级的.嵌入式的.关系型数据库 Android.IOS等广泛使用的的数据库系统 SQLite数据库之中可以方便的使用SQL语句,实现数据的增加.修改.删除.查询等操作 SQLiteOp ...
- MVC EF ObjectStateManager 中已存在具有同一键的对象。ObjectStateManager 无法跟踪具有相同键的多个对象。
遇到这个错误 在查询时 加上asNoTracking() 即可
- android View 绘制完成监听
<span style="font-size:18px">//view重绘时回调 view.getViewTreeObserver().addOnDrawListene ...
- win8升级win10后的windows.old怎么删除
现在win10只是出了预览版本,还没有出正式版,但是相信一部分朋友都与小D一样,喜欢尝鲜,已上用上了win10了. 有些人是通过win8或是8.1直接安装升级上去的,这样操作是安装方便,但是系统会为了 ...