# Install the Aerospike client

The two essential components of the PHP client are a robust PHP client written in Rust, and a connection manager written in Go. The connection manager daemon handles all requests and responses between the PHP processes and the Aerospike server.

## Prerequisites

-   [Aerospike database](https://aerospike.com/download/)
-   [PHP 8.1.0 or later](https://www.php.net/)
-   [PHPUnit v10](https://phpunit.de/index.html)
-   [Rustc >= v1.74](https://doc.rust-lang.org/rustc/what-is-rustc.html)
-   [Go Toolchain](https://go.dev/doc/toolchain)
-   [Protobuf Compiler](https://pkg.go.dev/google.golang.org/protobuf/cmd/protoc-gen-go)
-   [ext-php-rs v0.12.0](https://github.com/davidcole1340/ext-php-rs/tree/master)
-   [git](https://git-scm.com/)

## Building and installing the PHP client

### Set up dependencies

1.  Install PHP:
    
    Terminal window
    
    ```bash
    sudo apt-get install php
    
    sudo apt-get install php-dev
    ```
    
2.  Install Rust:
    
    Terminal window
    
    ```bash
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    
    . "$HOME/.cargo/env"
    ```
    
3.  Install `gcc` toolchain and linkers:
    
    Terminal window
    
    ```bash
    sudo apt-get install build-essential
    ```
    
4.  Install `clang`:
    
    Terminal window
    
    ```bash
    sudo apt-get install clang
    
    export LIBCLANG_PATH="/usr/lib/llvm-10/lib/"
    ```
    
5.  Install Go:
    
    Visit the [Go download page](https://go.dev/dl/) and follow the [installation instructions](https://go.dev/doc/install) for your platform.
    
6.  Install Go helpers:
    
    Terminal window
    
    ```bash
    go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
    
    sudo apt-get install -y protobuf-compiler
    
    go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
    ```
    

### Set up the PHP client and connection manager

1.  Verify that your [Aerospike server](https://aerospike.com/download/) is running and accessible.
    
2.  Clone the aerospike/php-client repository:
    
    Terminal window
    
    ```bash
    git clone https://github.com/aerospike/php-client.git
    ```
    
3.  Navigate to the `php-client/aerospike-connection-manager` directory.
    
    Terminal window
    
    ```bash
    cd php-client/aerospike-connection-manager
    ```
    
4.  Run the Makefile:
    
    Terminal window
    
    ```bash
    sudo make
    ```
    
5.  Navigate back up to the `php-client` directory.
    
    Terminal window
    
    ```bash
    cd ..
    ```
    
6.  Run the Makefile:
    
    To build and install `php-client` in the default path:
    
    Terminal window
    
    ```bash
    sudo make
    ```
    
    To build and install `php-client` manually:
    
    Terminal window
    
    ```bash
    cd php-client
    
    cargo clean && cargo build --release
    ```
    
    This generates a `.so` file for Ubuntu/RHEL/CentOS and `.dylib` for macOS in `/target/release` in the same directory. You can then manually add the extension to your PHP setup.
    
7.  Copy the file from `target/release/libaerospike.[EXTENSION]` (.EXTENSION = .so for Linux and .dylib for Mac and Windows) to the PHP extension directory path.
    
8.  Add `extension=libaerospike.[EXTENSION]` to your `php.ini` file.
    
9.  Run `phpunit tests/` to test the setup and build.
    
    ::: note
    The Aerospike Database must be running for the tests to run successfully.
    :::
    

See [Connecting](https://aerospike.com/docs/develop/client/php/connect/) for more information about configuring the connection manager.

## Running your PHP Project

-   Configure a client policy in the file `php-client/daemon/asld.toml` before starting the Aerospike Connection Manager.
    
    In the `asld.toml` file, for each `[cluster]` replace the placeholder values with the accessible address of your Aerospike server.
    
    Single-seed node:
    
    ```plaintext
    host = "127.0.0.1:3000"
    ```
    
    Multiple-seed node:
    
    ```plaintext
    host = "1.1.1.1:3001,2.2.2.2:3002,3.3.3.3"
    ```
    
    After configuring the `asld.toml` file, start the Aerospike Connection Manager to create a socket. The socket path can be modified in the `asld.toml` file.
    
-   The Aerospike server must be running. If the Aerospike server has security enabled, specify the username and password in the `asld.toml` file.
    
-   Import the Aerospike namespace to your PHP script.
    
    ```php
    namespace Aerospike;
    ```
    
-   To connect to the Aerospike connection manager, add the following to your script:
    
    ```php
    <?php
    
    namespace Aerospike;
    
    $socket = "/tmp/asld_grpc.sock";
    
    try{
    
      $client = Client::connect($socket);
    
      echo "* Connected to the local daemon: $client->socket \n";
    
    }catch(AerospikeException $e){
    
      echo "Failed connecting to Aerospike Server with Exception: ".$e;
    
    }
    ```
    
-   Run the script. If there are no errors, you have successfully connected to the Aerospike server.
    
    ::: note
    If the connection manager daemon crashes, you must manually delete the file `/tmp/asld_grpc.sock`.
    
    Terminal window
    
    ```bash
    sudo rm -r /tmp/asld_grpc.soc
    ```
    :::
    
-   Configuring policies (read, write, batch and info): you can set these policies via getters and setters in the PHP code. On creating an object of that policy class, the default values are initialized for that policy. For example:
    
    ```php
    // Instantiate the WritePolicy object
    
    $writePolicy = new WritePolicy();
    
    $writePolicy->setRecordExistsAction(RecordExistsAction::Update);
    
    $writePolicy->setGenerationPolicy(GenerationPolicy::ExpectGenEqual);
    
    $writePolicy->setExpiration(Expiration::seconds(3600)); // Expiring in 1 hour
    
    $writePolicy->setMaxRetries(3);
    
    $writePolicy->setSocketTimeout(5000);
    ```
    

## Server documentation

-   [Aerospike server documentation](https://aerospike.com/)

## Bug reporting

If you find bugs, create an issue on [GitHub](https://github.com/aerospike/php-client/issues).