Search code examples
phplaravelgrpcphp-extension

How to install 'ext-grpc' or 'grpc' on Ubuntu?


I was trying to install google/cloud-firestore package in my Laravel 10 project. Then I was getting this error.

Problem 1
    - google/cloud-firestore is locked to version v1.31.0 and an update of this package was not requested.
    - google/cloud-firestore v1.31.0 requires ext-grpc * -> it is missing from your system. Install or enable PHP's grpc extension.

I was trying to install this extension using the pecl on my system but that didn't work as I expected. I also added the extension=grpc.so in my php.ini file as well.


Solution

  • Understanding the Error:

    This error indicates that the google/cloud-firestore package (v1.31.0 in your case) requires the ext-grpc PHP extension, which is missing from your system. The ext-grpc extension enables communication with gRPC (remote procedure call) servers, essential for using Google Cloud Firestore in your Laravel application.

    Resolving the Issue:

    1. Verify PHP Version:

    Ensure you're using PHP 7.2 or later, as ext-grpc is not available for older versions. You can check your PHP version by running php -v in your terminal.

    1. Install ext-grpc Extension:

    If your system supports a package manager like apt, yum, or pecl, use the appropriate command to install the extension. Here are some examples:

            sudo apt install php8.1-grpc  # For Debian/Ubuntu (replace 8.1 with your PHP version)
    
            sudo yum install php-grpc      # For CentOS/RHEL
    
            pecl install grpc              # Using PECL
    
    1. Enable the Extension:

      • Edit your PHP configuration file (php.ini). The exact location may vary depending on your system. You can usually find it in /etc/php/8.1/cli/php.ini or use php --ini to locate it.

      • In the php.ini file, search for the line extension=grpc (or extension=php_grpc.dll for older PHP versions). If it's commented out (preceded by a semicolon ;), uncomment it by removing the semicolon.

      • Save the changes to php.ini.

    2. Restart PHP Server:

      • If you're using a web server like Apache or Nginx, restart it to reflect the changes made in php.ini. The exact command might vary depending on your server setup.
      • or you can restart the PHP using sudo systemctl restart php8.1-fpm
    3. Verify Installation:

      • Run php -i | grep grpc in your terminal. You should see output indicating the grpc extension is loaded.

    By following these steps carefully, you should be able to resolve the ext-grpc missing error and successfully use the google/cloud-firestore package in your Laravel 10 application.