Skip to content

Instantly share code, notes, and snippets.

@AndrewMast
Created October 24, 2025 20:02
Show Gist options
  • Select an option

  • Save AndrewMast/7fe160f51eb4477627e3be23a8e8391b to your computer and use it in GitHub Desktop.

Select an option

Save AndrewMast/7fe160f51eb4477627e3be23a8e8391b to your computer and use it in GitHub Desktop.
Laravel Forge Recipe to Install gRPC and Protobuf

Why gRPC?

My current web application requires me to use Firebase to authenticate and send push notifications to a mobile app. The best package that I've found that works is Jérôme Gamez's firebase-php and its Laravel package, laravel-firebase. All the other packages I have found either don't work or have not been updated in 5 years.

Unfortunately, in order to access Firebase's database (firestore) with the package, Google's google/cloud-firestore package is required. And that requires the grpc php extension.

Hosting

The grpc extension is pretty niche, at least when it comes to Laravel applications, so not many hosting options that I have found support it. Or at least first-party options like Laravel Vapor and Laravel Cloud have yet to add support.

Custom servers are the only option I have found that is viable, and luckily, Laravel Forge was recently revamped and added Laravel VPS servers that are pretty neat. Laravel Forge also has a very cool Recipe system to run bash scripts across on the servers it manages. This makes installing gRPC quite easy on Laravel Forge.

Installing

At the core, the "easiest" option to install gRPC is by using pecl: sudo pecl install grpc. However, there are a few issues with that. Firstly, it takes a long time to build. A really, really, long time. I'm talking more than an hour in some cases.

Additionally, every time I ran it on a small server (1GB / 2GB RAM), it would always fail. I kept getting the error g++: fatal error: Killed signal terminated program cc1plus, and after a bit of research, I decided to resize my Laravel VPS server to 4GB of ram to try to install gRPC.

It worked, but even after upscaling to a 4GB RAM Laravel VPS server, it took upwards of 75 minutes to install. And the inexperienced me didn't realize I can't downsize a Laravel VPS server.

Caution

You cannot downsize Laravel VPS servers to a smaller specification. You can only resize to a larger server size.

As I am still in the development phase, I'd rather not spend ~$25/mo on a 4GB server. After some more research, I found a thread that discussed the slow build times for gRPC and a few methods to speed it up, specifically in Docker environments.

One comment had a Docker script for a Debian-based environment that I was able to adapt for a server. The recipes that I made are based on this script. I am relatively new to installing things on servers myself, so if there are any issues with my recipes, please let me know so I can update them.

Using this method, I was able to install gRPC in as little as 3 minutes.

Recipes

Here are the two recipes I use. One to install gRPC, and one to install Protobuf. Protobuf is sometimes needed when using gRPC, but it may not be necessary for everyone.

Creating and using a Laravel Forge Recipe

  1. Navigate to the "Recipe" tab on the page for your organization.
  2. Hit the "+ New recipe" button.
  3. Provide a name, select the user to run the recipe, and enter the script.
  4. Once the recipe is created, hit the "Run" button on the recipe page.
  5. Select the servers you want to run the recipe on and then hit "Run".

Install gRPC Script

Name: Install gRPC, Run as: root

# Install all dependencies needed for gRPC compilation
sudo apt-get update && \
    apt-get install -y --no-install-recommends \
        git \
        make \
        libgrpc-dev \
        libgrpc++-dev \
        protobuf-compiler \
        build-essential \
        pkg-config \
        libssl-dev \
        zlib1g-dev \
        autoconf \
        automake \
        libtool \
        cmake \
    && rm -rf /var/lib/apt/lists/*

# Compile and install gRPC extension
sudo git clone --depth 1 -b v1.63.0 https://github.com/grpc/grpc /tmp/grpc && \
    cd /tmp/grpc/src/php/ext/grpc && \
    phpize && \
    ./configure && \
    make && \
    make install && \
    rm -rf /tmp/grpc && \
    apt-get autoremove -y && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

echo "Add 'extension=grpc' to both the PHP CLI and PHP-FPM configurations."
echo "Run 'php -m | grep grpc' in a terminal to check if it is properly set up."

Install Protobuf Script

Name: Install Protobuf, Run as: root

sudo pecl install protobuf

echo "Add 'extension=protobuf' to both the PHP CLI and PHP-FPM configurations."
echo "Run 'php -m | grep protobuf' in a terminal to check if it is properly set up."

Post-Install

Remember to add the extensions to both the PHP CLI and PHP-FPM configurations on your server!

  1. In Forge, navigate to your server's "PHP" tab.
  2. On the PHP settings page, hit the "..." button on the PHP version you have installed.
  3. Select "Edit PHP-FPM configuration".
  4. Add extension=grpc and/or extension=protobuf.
  5. Repeat for "Edit PHP CLI configuration".

I hope these scripts can be of use for you!

# Name: Install gRPC
# Run as: root
# Install all dependencies needed for gRPC compilation
sudo apt-get update && \
apt-get install -y --no-install-recommends \
git \
make \
libgrpc-dev \
libgrpc++-dev \
protobuf-compiler \
build-essential \
pkg-config \
libssl-dev \
zlib1g-dev \
autoconf \
automake \
libtool \
cmake \
&& rm -rf /var/lib/apt/lists/*
# Compile and install gRPC extension
sudo git clone --depth 1 -b v1.63.0 https://github.com/grpc/grpc /tmp/grpc && \
cd /tmp/grpc/src/php/ext/grpc && \
phpize && \
./configure && \
make && \
make install && \
rm -rf /tmp/grpc && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
echo "Add 'extension=grpc' to both the PHP CLI and PHP-FPM configurations."
echo "Run 'php -m | grep grpc' in a terminal to check if it is properly set up."
# Name: Install Protobuf
# Run as: root
sudo pecl install protobuf
echo "Add 'extension=protobuf' to both the PHP CLI and PHP-FPM configurations."
echo "Run 'php -m | grep protobuf' in a terminal to check if it is properly set up."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment