Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 100 lines (64 sloc) 3.367 kb
61d24ac Igor [docs] introduction chapter
igorw authored
1 # Introduction
2
3 Composer is a tool for dependency management in PHP. It allows you to declare
903eff1 Ryan Weaver Proofreading the first and second chapters of the very well-written docs
weaverryan authored
4 the dependent libraries your project needs and it will install them in your
5 project for you.
61d24ac Igor [docs] introduction chapter
igorw authored
6
7 ## Dependency management
8
903eff1 Ryan Weaver Proofreading the first and second chapters of the very well-written docs
weaverryan authored
9 Composer is not a package manager. Yes, it deals with "packages" or libraries, but
10 it manages them on a per-project basis, installing them in a directory (e.g. `vendor`)
11 inside your project. By default it will never install anything globally. Thus,
12 it is a dependency manager.
61d24ac Igor [docs] introduction chapter
igorw authored
13
903eff1 Ryan Weaver Proofreading the first and second chapters of the very well-written docs
weaverryan authored
14 This idea is not new and Composer is strongly inspired by node's [npm](http://npmjs.org/)
15 and ruby's [bundler](http://gembundler.com/). But there has not been such a tool
16 for PHP.
61d24ac Igor [docs] introduction chapter
igorw authored
17
caf2926 Ryan Weaver Tweaks per @igorw and @Seldaek. Biggest change is the capitalization of ...
weaverryan authored
18 The problem that Composer solves is this:
903eff1 Ryan Weaver Proofreading the first and second chapters of the very well-written docs
weaverryan authored
19
20 a) You have a project that depends on a number of libraries.
21
22 b) Some of those libraries depend on other libraries .
23
24 c) You declare the things you depend on
25
26 d) Composer finds out which versions of which packages need to be installed, and
caf2926 Ryan Weaver Tweaks per @igorw and @Seldaek. Biggest change is the capitalization of ...
weaverryan authored
27 installs them (meaning it downloads them into your project).
61d24ac Igor [docs] introduction chapter
igorw authored
28
29 ## Declaring dependencies
30
31 Let's say you are creating a project, and you need a library that does logging.
32 You decide to use [monolog](https://github.com/Seldaek/monolog). In order to
33 add it to your project, all you need to do is create a `composer.json` file
34 which describes the project's dependencies.
35
605fae4 Jordi Boggiano Remove fenced blocks in docs
Seldaek authored
36 {
37 "require": {
38 "monolog/monolog": "1.0.*"
39 }
61d24ac Igor [docs] introduction chapter
igorw authored
40 }
41
903eff1 Ryan Weaver Proofreading the first and second chapters of the very well-written docs
weaverryan authored
42 We are simply stating that our project requires some `monolog/monolog` package,
e825cea Igor [docs] basic usage chapter
igorw authored
43 any version beginning with `1.0`.
61d24ac Igor [docs] introduction chapter
igorw authored
44
45 ## Installation
46
1a32b15 Jordi Boggiano Fix docs
Seldaek authored
47 ### Downloading the Composer Executable
903eff1 Ryan Weaver Proofreading the first and second chapters of the very well-written docs
weaverryan authored
48
3068e92 Grégoire Pineau [Doc] Added a note to install composer globally
lyrixx authored
49 #### Locally
50
903eff1 Ryan Weaver Proofreading the first and second chapters of the very well-written docs
weaverryan authored
51 To actually get Composer, we need to do two things. The first one is installing
caf2926 Ryan Weaver Tweaks per @igorw and @Seldaek. Biggest change is the capitalization of ...
weaverryan authored
52 Composer (again, this mean downloading it into your project):
61d24ac Igor [docs] introduction chapter
igorw authored
53
990a36a Matthew Weier O'Phinney Update doc/00-intro.md
weierophinney authored
54 $ curl -s https://getcomposer.org/installer | php
61d24ac Igor [docs] introduction chapter
igorw authored
55
56 This will just check a few PHP settings and then download `composer.phar` to
caf2926 Ryan Weaver Tweaks per @igorw and @Seldaek. Biggest change is the capitalization of ...
weaverryan authored
57 your working directory. This file is the Composer binary. It is a PHAR (PHP
903eff1 Ryan Weaver Proofreading the first and second chapters of the very well-written docs
weaverryan authored
58 archive), which is an archive format for PHP which can be run on the command
59 line, amongst other things.
61d24ac Igor [docs] introduction chapter
igorw authored
60
caf2926 Ryan Weaver Tweaks per @igorw and @Seldaek. Biggest change is the capitalization of ...
weaverryan authored
61 You can install Composer to a specific directory by using the `--install-dir`
1ee715e Wil Moore III updated intro and basic-usage to reflect new --install-dir option
wilmoore authored
62 option and providing a target directory (it can be an absolute or relative path):
63
990a36a Matthew Weier O'Phinney Update doc/00-intro.md
weierophinney authored
64 $ curl -s https://getcomposer.org/installer | php -- --install-dir=bin
1ee715e Wil Moore III updated intro and basic-usage to reflect new --install-dir option
wilmoore authored
65
3068e92 Grégoire Pineau [Doc] Added a note to install composer globally
lyrixx authored
66 #### Globally
67
903eff1 Ryan Weaver Proofreading the first and second chapters of the very well-written docs
weaverryan authored
68 You can place this file anywhere you wish. If you put it in your `PATH`,
69 you can access it globally. On unixy systems you can even make it
70 executable and invoke it without `php`.
71
6375bc5 Kyle Robinson Young Typo fixes
shama authored
72 You can run these commands to easily access `composer` from anywhere on your system:
3068e92 Grégoire Pineau [Doc] Added a note to install composer globally
lyrixx authored
73
990a36a Matthew Weier O'Phinney Update doc/00-intro.md
weierophinney authored
74 $ curl -s https://getcomposer.org/installer | php
3068e92 Grégoire Pineau [Doc] Added a note to install composer globally
lyrixx authored
75 $ sudo mv composer.phar /usr/local/bin/composer
76
77 Then, just run `composer` in order to run composer
78
1a32b15 Jordi Boggiano Fix docs
Seldaek authored
79 ### Using Composer
903eff1 Ryan Weaver Proofreading the first and second chapters of the very well-written docs
weaverryan authored
80
133f331 Daniel Mecke fixed typo
dmecke authored
81 Next, run the `install` command to resolve and download dependencies:
61d24ac Igor [docs] introduction chapter
igorw authored
82
83 $ php composer.phar install
84
903eff1 Ryan Weaver Proofreading the first and second chapters of the very well-written docs
weaverryan authored
85 This will download monolog into the `vendor/monolog/monolog` directory.
61d24ac Igor [docs] introduction chapter
igorw authored
86
87 ## Autoloading
88
caf2926 Ryan Weaver Tweaks per @igorw and @Seldaek. Biggest change is the capitalization of ...
weaverryan authored
89 Besides downloading the library, Composer also prepares an autoload file that's
903eff1 Ryan Weaver Proofreading the first and second chapters of the very well-written docs
weaverryan authored
90 capable of autoloading all of the classes in any of the libraries that it
91 downloads. To use it, just add the following line to your code's bootstrap
92 process:
61d24ac Igor [docs] introduction chapter
igorw authored
93
22fe296 Jordi Boggiano Move .composer files out into the vendor dir, fixes #497
Seldaek authored
94 require 'vendor/autoload.php';
61d24ac Igor [docs] introduction chapter
igorw authored
95
caf2926 Ryan Weaver Tweaks per @igorw and @Seldaek. Biggest change is the capitalization of ...
weaverryan authored
96 Woh! Now start using monolog! To keep learning more about Composer, keep
903eff1 Ryan Weaver Proofreading the first and second chapters of the very well-written docs
weaverryan authored
97 reading the "Basic Usage" chapter.
cee5fed Travis Northcutt added prev/next links to docs
tnorthcutt authored
98
99 [Basic Usage](01-basic-usage.md) →
Something went wrong with that request. Please try again.