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