1[[installation]]
2== Installation
3
4Elasticsearch-php only has a three requirements that you need to worry about:
5
6* PHP 7.0.0 or higher
7* http://getcomposer.org[Composer]
8* http://php.net/manual/en/book.curl.php[ext-curl]: the Libcurl extension for PHP (see note below)
9* Native JSON Extensions (`ext-json`) 1.3.7 or higher
10
11The rest of the dependencies will automatically be downloaded and installed by Composer.  Composer is a package and dependency manager for PHP.  Installing elasticsearch-php with Composer is very easy
12
13[NOTE]
14.Libcurl can be replaced
15====
16The default HTTP handlers that ship with Elasticsearch-php require the PHP libcurl extension, but it is not technically
17required for the client to operate.  If you have a host that does not have libcurl installed, you can use an
18alternate HTTP handler based on PHP streams.  Performance _will_ suffer, as the libcurl extension is much faster
19====
20
21=== Version Matrix
22
23You need to match your version of Elasticsearch to the appropriate version of this library.
24
25The master branch will always track Elasticsearch master, but it is not recommended to use `dev-master` in your production code.
26
27[width="40%",options="header",frame="topbot"]
28|============================
29|Elasticsearch Version | Elasticsearch-PHP Branch
30| >= 7.0, < 8.0        | `7.0`
31| >= 6.6, <= 6.7       | `6.7.x`
32| >= 6.0, <= 6.5       | `6.5.c`
33| >= 5.0, < 6.0        | `5.0`
34| >= 1.0, < 5.0        | `1.0`, `2.0`
35| <= 0.90.*            | `0.4`
36|============================
37
38=== Composer Installation
39
40* Include elasticsearch-php in your `composer.json` file.  If you are starting a new project, simply paste the following JSON snippet into a new file called `composer.json`.  If you have an existing project, include this requirement under the rest of requirements already present:
41+
42[source,json]
43--------------------------
44{
45    "require": {
46        "elasticsearch/elasticsearch": "~7.0"
47    }
48}
49--------------------------
50
51* Install the client with composer.  The first command download the `composer.phar` PHP package, and the second command invokes the installation.  Composer will automatically download any required dependencies, store them in a /vendor/ directory and build an autoloader.:
52+
53[source,shell]
54--------------------------
55curl -s http://getcomposer.org/installer | php
56php composer.phar install --no-dev
57--------------------------
58+
59More information about http://getcomposer.org/[Composer can be found at their website].
60
61* Finally, include the generated autoloader in your main project.  If your project is already based on Composer, the autoloader is likely already included somewhere and you don't need to add it again.  Finally, instantiate a new client:
62+
63[source,php]
64--------------------------
65require 'vendor/autoload.php';
66
67$client = Elasticsearch\ClientBuilder::create()->build();
68--------------------------
69+
70Client instantiation is performed with a static helper function `create()`.  This creates a ClientBuilder object,
71which helps you to set custom configurations.  When you are done configuring, you call the `build()` method to generate
72a `Client` object.  We'll discuss configuration more in the Configuration section
73
74
75=== --no-dev flag
76You'll notice that the installation command specified `--no-dev`.  This prevents Composer
77from installing the various testing and development dependencies.  For average users, there
78is no need to install the test suite.  In particular, the development dependencies include
79a full copy of Elasticsearch so that tests can be run against the REST specifications.  This
80is a rather large download for non-developers, hence the --no-dev flag
81
82If you wish to contribute to development of this library, just omit the `--no-dev` flag to
83be able to run tests.
84