How To Install PHP Client For Elasticsearch On Windows
Introduction
In this guide, it will be explained how to install PHP client Elasticsearch Windows OS. This is one of a list of tools found in the Elastic Stack. The steps below will walk the user through a complete setup for Windows. The PHP client will enhance the accuracy of retrieved data through Elasticsearch. Follow the simple process below to experience the dynamic power this software enables the user to wield in their queries.
>The Elasticsearch-PHP library is lightweight, easily installed via the Composer PHP dependency manager, and allows for one-to-one mapping wit
Prerequisites:
Note php client library for Elasticsearch has several requirements:
64-bit version of Windows 7 or 10 (Elastic does not support 32-bit architecture)
PHP 7 or higher is recommended for Composer and the PHP client
Composer
ext-curl
Libcurl extensionext-json
Native JSON ExtensionJava and JDK 8 installed
The remaining dependencies are downloaded and installed by Composer automatically.
- Be mindful to match the version of Elasticsearch to the appropriate version of this library. Generally speaking, the major version number of the PHP library should match its respective Elasticsearch version (i.e. Only install Elasticsearch-PHP 4.x branch on a machine with Elasticsearch 4.x installed)
elasticsearch-php
library for Elasticsearch
Installing PHP in Windows
Windows 10 does not come with PHP installed.
Download the latest version of PHP 7 for 64-bit Windows directly from the windows.php.net website, and then extract the folder using a file archiver program like 7-Zip.
Installing Java Development Kit (JDK) 8
Java 1.8 release series is recommended to be installed to run Elasticsearch. Only Elasticsearch v6.2, or newer, has JDK 9 support. h
Check the version installed by visiting the Java Control Panel that’s listed in the Start menu’s programs.
Inside the Java Control Panel, more information can be found by clicking the About tab to get:
- To select a Java version to run as the default, configure the
JAVA_HOME
environment variable. Just right clickMy Computer
and selectProperties
. Once there, click on theAdvanced
tab, and select theEnvironment Variables
to edit theJAVA_HOME
variable to point at the JDK software location, for example:C:\Program Files\Java\jdk1.X.X
(make sure to replaceX
with the proper version number for the installed JDK).
Installing Composer from GUI (Graphic-User-Interface)
Download the installer file via Composer’s Download page
Run the installer by double clicking the
composer .exe
fileThe setup window will appear, just click next
Specify PHP 7 executable that Composer will use for command-line. Navigate to the
php.exe
file in the directory (for example:C:\php7\php
).
- If using proxy server, then check the option, otherwise just click next > to continue.
- Next setup window will display the installation setting(s) created from the previous steps. Click “Install” to continue.
- The Composer installer will initiate the installation process and will download related components.
- The installer will inform the user that the
Windows Environment
has been changed. This enables composer to now be run via command prompt.
Below are the changes that Composer made to the system environment.
In the User Variables section the
PATH
variable can be set with the location value of Composer’s binary file. The path should be inthevendor
directory, like in this example:
1 | (C:\Users\ElasticUser\AppData\Roaming\Composer\vendor\bin) |
“System Variables” section: PATH variable with a location value of
php.exe
file (e.g.C:\php7\php\php.exe
).To acknowledge that the installation is now completed click finish.
Test Composer in command prompt by typing:
1 | composer --version |
Installing cURL
_>_Note! It is possible that nothing needs to be downloaded: If on Windows 10, version 1803 or later, the OS ships with a copy of curl that has already been set up and is ready to be used. If Git is installed (if Git was downloaded at git-scm.com, then yes), curl.exe is what it is under:
1 | C:\Program Files\Git\mingw64\bin\ |
Add what is above to PATH.
The right package for windows build will have to be downloaded through curl’s website.
locate curl.exe under
bin\
of the downloaded package.Give the curl a folder within the preferred location in the hard drive.
1 | C:\Program Files\curl or C:\url |
Put the curl.exe under that folder and be sure to never move it or its content.
Ensure that curl is available from anywhere using the command line with the following steps.
On the windows system start menu, type
"environment"
.Notice the search result
" Edit system environment variables"
then select it.A System Properties window will open, then click the
"Environment Variables"
button found at the bottom border of the window.Select the
"PATH"
under"System Variables"
then click"Edit"
.Click
"Add"
button located on the right aside panel and paste the location in the folder path where the curl lives(i.e C:url).Click
"Ok"
to finish.
Install Composer Via Command Line
Add elasticsearch/elasticsearch
as a dependency in the project’s composer.json
file (change version to match installation):
1 2 3 4 5 | { "require": { "elasticsearch/elasticsearch": "~6.0" } } |
Download and install Composer:
1 | curl -s http://getcomposer.org/installer | php |
Install dependencies:
1 | php composer.phar install |
Require Autoloader in Composer:
Composer also can prepare an autoload file that is capable of handling all classes in any library it downloads. To make use of it, simply add the line below to the code’s bootstrap process:
1 2 3 4 5 6 7 | <?php use Elasticsearch\ClientBuilder; require 'vendor/autoload.php'; $client = ClientBuilder::create()->build(); |
Conclusion
In this article, the basic elements of a successful install for PHP client are detailed. Above, the reader will find other pointers and helpful links to assist during the setup. Supporting documents can also be found linked to throughout the preceding instructions. If more in-depth information is required, the manufacturer can accommodate on their website. Before looking somewhere else for help, try some of the other guides found here or at one of the sources linked to below.
Pilot the ObjectRocket Platform Free!
Try Fully-Managed CockroachDB, Elasticsearch, MongoDB, PostgreSQL (Beta) or Redis.
Get Started