Install gRPC for PHP


  • Install and enable the gRPC extension for PHP.


  • PHP 5.5 and above or PHP 7.0 and above
  • PECL (Unless you build from source)
  • Composer

Install PECL

Ubuntu / Debian

For PHP5

sudo apt-get install php5-dev php-pear phpunit

For PHP7

sudo apt-get install php7.0-dev php-pear phpunit

CentOS / RHEL 7

 sudo rpm -Uvh
 sudo rpm -Uvh
 sudo yum install php56w-devel php-pear phpunit gcc zlib-devel


 curl -O
 sudo php -d detect_unicode=0 go-pear.phar

Install Composer

Linux or Mac

curl -sS | php
sudo mv composer.phar /usr/local/bin/composer

Install the gRPC extension

Using PECL

sudo pecl install grpc

This compiles and installs the gRPC PHP extension into the standard PHP extension directory.

Build from Source

Follow these instructions to compile the gRPC core library and PHP extension from source.

  1. Clone the gRPC repository from GitHub.

    git clone -b $(curl -L
  2. Build and install the gRPC C core library.

    cd grpc
    git pull --recurse-submodules && git submodule update --init --recursive
    sudo make install
  3. Compile the gRPC PHP extension

    cd src/php/ext/grpc
    sudo make install

Enable the gRPC extension in php.ini

Add this line to your php.ini file, e.g. /etc/php5/cli/php.ini

Add gRPC as a Composer dependency

Require the grpc/grpc package using Composer.

composer require "grpc/grpc:^v1.1.0"

Install the Protobuf Runtime library

There are two protobuf runtime libraries to choose from. They are identical in terms of APIs offered. The C implementation provides better performance, while the native implementation is easier to install.

C Implementation

For better performance with gRPC, install the extension using PECL.

sudo pecl install protobuf

Now add this line to your php.ini file, e.g. /etc/php5/cli/php.ini

PHP implementation

For easier installation, simply require the google/protobuf package using Composer.

composer require "google/protobuf:^v3.3.0"

Next Steps

Now that gRPC and the gRPC PHP extension are installed, try out gRPC-enabled APIs such as Cloud Spanner.

Was this page helpful? Let us know how we did:

Send feedback about...