1
0
Fork 0
composer/doc/00-intro.md

172 lines
5.5 KiB
Markdown
Raw Normal View History

2012-02-18 12:34:07 +00:00
# Introduction
Composer is a tool for dependency management in PHP. It allows you to declare
2015-06-22 12:31:33 +00:00
the libraries your project depends on and it will manage (install/update) them
for you.
2012-02-18 12:34:07 +00:00
## Dependency management
2015-06-22 12:31:33 +00:00
Composer is **not** a package manager in the same sense as Yum or Apt are. 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.
2012-02-18 12:34:07 +00:00
2015-06-22 12:31:33 +00:00
This idea is not new and Composer is strongly inspired by node's
[npm](https://npmjs.org/) and ruby's [bundler](http://bundler.io/).
2012-02-18 12:34:07 +00:00
2015-06-22 12:31:33 +00:00
Suppose:
a) You have a project that depends on a number of libraries.
2013-07-01 00:52:10 +00:00
b) Some of those libraries depend on other libraries.
2015-06-22 12:31:33 +00:00
Composer:
2015-06-22 12:31:33 +00:00
c) Enables you to declare the libraries you depend on.
2012-02-18 12:34:07 +00:00
2015-06-22 12:31:33 +00:00
d) Finds out which versions of which packages can and need to be installed, and
installs them (meaning it downloads them into your project).
2012-02-18 12:34:07 +00:00
2015-06-22 12:31:33 +00:00
See the [Basic usage](01-basic-usage.md) chapter for more details on declaring
dependencies.
2012-02-18 12:34:07 +00:00
## System Requirements
Composer requires PHP 5.3.2+ to run. A few sensitive php settings and compile
2015-06-22 12:31:33 +00:00
flags are also required, but when using the installer you will be warned 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.
2014-12-13 18:05:52 +00:00
## Installation - Linux / Unix / OSX
2014-12-13 17:59:14 +00:00
2012-03-20 11:50:23 +00:00
### Downloading the Composer Executable
2015-06-30 06:43:54 +00:00
Composer offers a convenient installer that you can execute directly from the
commandline. Feel free to [download this file](https://getcomposer.org/installer)
or review it on [GitHub](https://github.com/composer/getcomposer.org/blob/master/web/installer)
if you wish to know more about the inner workings of the installer. The source
is plain PHP.
2014-12-13 18:05:52 +00:00
There are in short, two ways to install Composer. Locally as part of your
2014-12-13 17:59:14 +00:00
project, or globally as a system wide executable.
#### Locally
2014-12-13 17:59:14 +00:00
Installing Composer locally is a matter of just running the installer in your
project directory:
2012-02-18 12:34:07 +00:00
```sh
curl -sS https://getcomposer.org/installer | php
```
> **Note:** If the above fails for some reason, you can download the installer
> with `php` instead:
```sh
php -r "readfile('https://getcomposer.org/installer');" | php
```
2012-02-18 12:34:07 +00:00
2015-06-22 12:31:33 +00:00
The installer 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.
2012-02-18 12:34:07 +00:00
Now just run `php composer.phar` in order to run Composer.
You can install Composer to a specific directory by using the `--install-dir`
option and additionally (re)name it as well using the `--filename` option:
```sh
curl -sS https://getcomposer.org/installer | php -- --install-dir=bin --filename=composer
```
Now just run `php bin/composer` in order to run Composer.
2015-06-22 12:31:33 +00:00
#### Globally
2015-06-22 12:31:33 +00:00
You can place the Composer PHAR anywhere you wish. If you put it in a directory
that is part of your `PATH`, you can access it globally. On unixy systems you
can even make it executable and invoke it without directly using the `php`
interpreter.
2015-06-22 12:31:33 +00:00
Run these commands to globally install `composer` on your system:
```sh
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
```
2015-06-30 06:43:54 +00:00
> **Note:** If the above fails due to permissions, run the `mv` line again
> with sudo.
A quick copy-paste version including sudo:
```sh
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
```
2013-04-17 17:21:44 +00:00
2015-06-22 12:31:33 +00:00
> **Note:** On some versions of OSX the `/usr` directory does not exist by
> default. If you receive the error "/usr/local/bin/composer: No such file or
> directory" then you must create the directory manually before proceeding:
> `mkdir -p /usr/local/bin`.
2015-06-22 12:31:33 +00:00
> **Note:** For information on changing your PATH, please read the
> [Wikipedia article](https://en.wikipedia.org/wiki/PATH_(variable)) and/or use Google.
Now just run `composer` in order to run Composer instead of `php composer.phar`.
## Installation - Windows
2012-10-25 13:17:35 +00:00
### Using the Installer
This is the easiest way to get Composer set up on your machine.
2015-06-22 12:31:33 +00:00
Download and run
[Composer-Setup.exe](https://getcomposer.org/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.
2012-10-25 13:17:35 +00:00
2015-06-22 12:31:33 +00:00
> **Note:** Close your current terminal. Test usage with a new terminal: This is
> important since the PATH only gets loaded when the terminal starts.
2014-11-25 16:01:07 +00:00
2012-10-25 13:17:35 +00:00
### Manual Installation
Change to a directory on your `PATH` and run the install snippet to download
2015-06-22 12:31:33 +00:00
`composer.phar`:
```sh
C:\Users\username>cd C:\bin
C:\bin>php -r "readfile('https://getcomposer.org/installer');" | php
```
2013-10-16 14:24:48 +00:00
2015-06-22 12:31:33 +00:00
> **Note:** If the above fails due to readfile, use the `http` url or enable
> php_openssl.dll in php.ini
2013-07-01 00:52:10 +00:00
Create a new `composer.bat` file alongside `composer.phar`:
```sh
C:\bin>echo @php "%~dp0composer.phar" %*>composer.bat
```
2012-10-25 13:17:35 +00:00
2015-06-02 13:47:52 +00:00
Add the directory to your PATH environment variable if it isn't already.
Close your current terminal. Test usage with a new terminal:
```sh
C:\Users\username>composer -V
Composer version 27d8904
```
## Using Composer
2015-06-22 12:31:33 +00:00
Now that you've installed Composer, you are ready to use it! Head on over to the
next chapter for a short and simple demonstration.
2012-03-07 16:35:53 +00:00
2015-06-22 12:31:33 +00:00
[Basic usage](01-basic-usage.md) →