With composer (Recommended)
Install the package via Composer:
composer require algolia/algoliasearch-client-php
If you don’t use Composer, you can download the package and include it in your code.
If you’re a Symfony or Laravel user, you’re probably looking for the following integrations:
To begin, you will need to initialize the client. In order to do this you will need your Application ID and API Key. You can find both on your Algolia account.
<?php // composer autoload require __DIR__ . '/vendor/autoload.php'; // if you are not using composer // require_once 'path/to/algoliasearch.php'; $client = new \AlgoliaSearch\Client('YourApplicationID', 'YourAdminAPIKey'); $index = $client->initIndex('your_index_name');
You need to replace
index_name by the name of the index you want to use. If you want to target an existing index you can find the name from the dashboard. If the index does not exist you can choose any name and it will be created when you perform an add objects or a set settings operation.
If an api key is displayed in the previous snippet it is your ADMIN API Key. To maintain security, never use your ADMIN API Key on your frontend or share it with anyone. In your frontend, use the SEARCH ONLY API Key or any other key that has search only rights.
Did you find this page helpful?
We're always looking for advice to help improve our documentation!
Please let us know what's working (or what's not!).
We're constantly iterating thanks to the feedback we receive.