Stay organized with collections
Save and categorize content based on your preferences.
gRPC is a modern, open-source, high-performance remote procedure call framework.
If you want to use PHP client libraries for gRPC-enabled APIs, you must install
gRPC for PHP. This tutorial explains how to install and enable 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.
Clone the gRPC repository from GitHub.
git clone https://github.com/grpc/grpc
Build and install the gRPC C core library.
cd grpcgit submodule update --initmakesudo make installIt can take a few minutes to download and execute the library.If you have git version 1.8.4 or greater, you can speed upthe `git submodule update --init` command by adding the `--depth=1`flag.
Compile the gRPC PHP extension.
cd src/php/ext/grpcphpize./configuremakesudo make install
Windows
Windows users can download the pre-compiled gRPC directly from the
PECL website.
Add this line anywhere in your php.ini file, for example, /etc/php7/cli/php.ini.
You can find this file by running php --ini.
extension=grpc.so
Windows
Add this line anywhere in your php.ini file, for example, C:\Program Files\PHP\7.3\php.ini.
extension=php_grpc.dll
Add gRPC as a Composer dependency
Use Composer to add the grpc/grpc package to your PHP project:
composerrequire"grpc/grpc:^1.38"
Installing the protobuf runtime library
You can choose from two protobuf runtime libraries. The APIs they offer are
identical. The C implementation performs better than the PHP (native)
implementation, while the native implementation installs easier than the
C implementation.
C implementation
For better performance with gRPC, enable the protobuf C-extension.
Linux / macOS
Install the protobuf.so extension by using PECL.
sudo pecl install protobuf
Now add this line to your php.ini file, for example,
/etc/php5/cli/php.ini.
extension=protobuf.so
Windows
Download the pre-compiled protobuf extension directly from the
PECL website.
Now add this line to your php.ini file, for example,
C:\Program Files\PHP\7.3\php.ini.
extension=php_protobuf.dll
PHP implementation
For easier installation, require the google/protobuf package by using
Composer.
composer require "google/protobuf:^3.17"
What's next
Now that you've installed gRPC and the gRPC PHP extension, try out gRPC-enabled
APIs such as
Spanner.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[],[],null,["# Install gRPC for PHP\n\ngRPC is a modern, open-source, high-performance remote procedure call framework.\nIf you want to use PHP client libraries for gRPC-enabled APIs, you must install\ngRPC for PHP. This tutorial explains how to install and enable gRPC.\n\nObjectives\n----------\n\n- Install the gRPC extension for PHP.\n- Enable the gRPC extension for PHP.\n\nRequirements\n------------\n\n- PHP 7.0 or later\n- [PECL](https://pecl.php.net/) (unless you build from source)\n- [Composer](https://getcomposer.org/)\n\n| **Note:** Windows users can [download and enable DLLs](https://pecl.php.net/package/gRPC) from PECL.\n\nInstalling PECL\n---------------\n\n### Ubuntu / Debian\n\n sudo apt-get install autoconf zlib1g-dev php-dev php-pear\n\nIf using PHP 7.4+, PHP must have been installed with the `--with-pear` flag.\n\n### CentOS / RHEL 7\n\n sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm\n sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm\n sudo yum install php-devel php-pear gcc zlib-devel\n\n### macOS\n\n curl -O https://pear.php.net/go-pear.phar\n sudo php -d detect_unicode=0 go-pear.phar\n\n### Windows\n\nWindows does not require PECL.\n\nInstalling Composer\n-------------------\n\n### Linux\n\n curl -sS https://getcomposer.org/installer | php\n sudo mv composer.phar /usr/local/bin/composer\n\n### macOS\n\n curl -sS https://getcomposer.org/installer | php\n sudo mv composer.phar /usr/local/bin/composer\n\n### Windows\n\nFollow the [official Composer installation instructions](https://getcomposer.org/doc/00-intro.md#installation-windows)\nfor Windows.\n\nInstalling the gRPC extension\n-----------------------------\n\n### Using PECL\n\n sudo pecl install grpc\n\nThis compiles and installs the gRPC PHP extension into the standard PHP\nextension directory.\n| **Note:** For users on CentOS/RHEL 6, unfortunately this step won't work. Follow the instructions under the **Build from source** tab to compile the extension from source.\n\n### Build from source\n\nFollow these instructions to compile the gRPC core library and PHP extension\nfrom source.\n\n1. Clone the gRPC repository from GitHub.\n\n git clone https://github.com/grpc/grpc\n\n2. Build and install the gRPC C core library.\n\n cd grpc\n git submodule update --init\n make\n sudo make install\n\n It can take a few minutes to download and execute the library.\n If you have git version 1.8.4 or greater, you can speed up\n the `git submodule update --init` command by adding the `--depth=1`\n flag.\n\n3. Compile the gRPC PHP extension.\n\n cd src/php/ext/grpc\n phpize\n ./configure\n make\n sudo make install\n\n### Windows\n\nWindows users can download the pre-compiled gRPC directly from the\n[PECL website](https://pecl.php.net/package/grpc).\n\nRead the [PHP documentation for installing extensions](https://www.php.net/manual/en/install.pecl.windows.php) on Windows.\n\n### Enable the gRPC extension in php.ini\n\n### Linux / macOS\n\n\nAdd this line anywhere in your `php.ini` file, for example, `/etc/php7/cli/php.ini`.\nYou can find this file by running `php --ini`. \n\n extension=grpc.so\n\n### Windows\n\nAdd this line anywhere in your `php.ini` file, for example, `C:\\Program Files\\PHP\\7.3\\php.ini`. \n\n extension=php_grpc.dll\n\n### Add gRPC as a Composer dependency\n\nUse Composer to add the `grpc/grpc` package to your PHP project: \n\n composer require \"grpc/grpc:^1.38\"\n\nInstalling the protobuf runtime library\n---------------------------------------\n\nYou can choose from two protobuf runtime libraries. The APIs they offer are\nidentical. The C implementation performs better than the PHP (native)\nimplementation, while the native implementation installs easier than the\nC implementation. \n\n### C implementation\n\nFor better performance with gRPC, enable the protobuf C-extension.\n\n**Linux / macOS**\n\nInstall the `protobuf.so` extension by using PECL. \n\n sudo pecl install protobuf\n\nNow add this line to your `php.ini` file, for example,\n`/etc/php5/cli/php.ini`. \n\n extension=protobuf.so\n\n**Windows**\n\nDownload the pre-compiled protobuf extension directly from the\n[PECL website](https://pecl.php.net/package/protobuf).\n\nNow add this line to your `php.ini` file, for example,\n`C:\\Program Files\\PHP\\7.3\\php.ini`. \n\n extension=php_protobuf.dll\n\n### PHP implementation\n\nFor easier installation, require the `google/protobuf` package by using\nComposer. \n\n composer require \"google/protobuf:^3.17\"\n\nWhat's next\n-----------\n\nNow that you've installed gRPC and the gRPC PHP extension, try out gRPC-enabled\nAPIs such as\n[Spanner](/spanner/docs/reference/libraries#client-libraries-install-php)."]]