How to install the protocol buffer compiler.
While not mandatory, gRPC applications often leverage Protocol Buffers for service definitions and data serialization. Most of the example code from this site uses version 3 of the protocol buffer language (proto3).
The protocol buffer compiler, protoc
, is used to compile .proto
files, which contain service and message definitions. Choose one of the methods given below to install protoc.
Install pre-compiled binaries (any OS)
To install the latest release of the protocol compiler from pre-compiled binaries, follow these instructions:
-
Manually download from github.com/google/protobuf/releases the zip file corresponding to your operating system and computer architecture (
protoc-<version>-<os>-<arch>.zip
), or fetch the file using commands such as the following:# cd /root # curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v22.0/protoc-22.0-linux-x86_64.zip
-
Unzip the file under
$HOME/.local
or a directory of your choice. For example:# unzip protoc-22.0-linux-x86_64.zip -d $HOME/.local
-
Update your environment’s path variable to include the path to the
protoc
executable and add below line in php.ini file. For example:# export PATH="$PATH:$HOME/.local/bin"
echo "extension=protobuf.so" >> /etc/php.ini
Other installation options
If you’d like to build the protocol compiler from sources, or access older
versions of the pre-compiled binaries, see Download Protocol
Buffers.