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

158 lines
5.7 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 does not install anything globally. Thus, it is a dependency
manager. It does however support a "global" project for convenience via the
[global](03-cli.md#global) command.
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://www.npmjs.com/) and ruby's [bundler](https://bundler.io/).
2012-02-18 12:34:07 +00:00
2015-06-22 12:31:33 +00:00
Suppose:
1. You have a project that depends on a number of libraries.
1. Some of those libraries depend on other libraries.
2015-06-22 12:31:33 +00:00
Composer:
1. Enables you to declare the libraries you depend on.
1. Finds out which versions of which packages can and need to be installed, and
2015-06-22 12:31:33 +00:00
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
2016-06-22 05:19:29 +00:00
git, svn, fossil 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,
2018-09-27 11:00:10 +00:00
Linux and macOS.
2018-09-27 11:00:10 +00:00
## Installation - Linux / Unix / macOS
2012-02-18 12:34:07 +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
command line. Feel free to [download this file](https://getcomposer.org/installer)
2015-06-30 06:43:54 +00:00
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
2018-03-23 10:37:33 +00:00
To install Composer locally, run the installer in your project directory. See
[the Download page](https://getcomposer.org/download/) for instructions.
2012-02-18 12:34:07 +00:00
2018-03-23 10:37:33 +00:00
The installer will 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
2015-06-22 12:31:33 +00:00
the command line, amongst other things.
2012-02-18 12:34:07 +00:00
2018-03-23 10:37:33 +00:00
Now run `php composer.phar` in order to run Composer.
2012-02-18 12:34:07 +00:00
You can install Composer to a specific directory by using the `--install-dir`
2016-02-10 18:41:13 +00:00
option and additionally (re)name it as well using the `--filename` option. When
running the installer when following
[the Download page instructions](https://getcomposer.org/download/) add the
following parameters:
```sh
2016-02-10 18:41:13 +00:00
php composer-setup.php --install-dir=bin --filename=composer
```
2018-03-23 10:37:33 +00:00
Now 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 Unix systems you
2015-06-22 12:31:33 +00:00
can even make it executable and invoke it without directly using the `php`
interpreter.
2016-02-10 18:41:13 +00:00
After running the installer following [the Download page instructions](https://getcomposer.org/download/)
you can run this to move composer.phar to a directory that is in your path:
```sh
mv composer.phar /usr/local/bin/composer
```
If you like to install it only for your user and avoid requiring root permissions,
you can use `~/.local/bin` instead which is available by default on some
Linux distributions.
2016-02-10 18:41:13 +00:00
> **Note:** If the above fails due to permissions, you may need to run it again
2015-06-30 06:43:54 +00:00
> with sudo.
2013-04-17 17:21:44 +00:00
2018-09-27 11:00:10 +00:00
> **Note:** On some versions of macOS the `/usr` directory does not exist by
2015-06-22 12:31:33 +00:00
> 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
> your search engine of choice.
2015-06-22 12:31:33 +00:00
2018-03-23 10:37:33 +00:00
Now 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
2018-03-23 10:37:33 +00:00
install the latest Composer version and set up your PATH so that you can
2015-06-22 12:31:33 +00:00
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
2016-02-10 18:41:13 +00:00
Change to a directory on your `PATH` and run the installer following
[the Download page instructions](https://getcomposer.org/download/)
to download `composer.phar`.
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.
2016-02-10 18:41:13 +00:00
For information on changing your PATH variable, please see
2017-12-29 10:33:19 +00:00
[this article](https://www.computerhope.com/issues/ch000549.htm) and/or
use your search engine of choice.
Close your current terminal. Test usage with a new terminal:
```sh
C:\Users\username>composer -V
2016-02-10 18:41:13 +00:00
Composer version 1.0.0 2016-01-10 20:34:53
```
## 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) →