gRPC working in terminal but not in laravel project

Viewed 809

I already installed gRPC following this instruction from google https://cloud.google.com/php/grpc.

I added these two lines

extension=protobuf.so
extension=grpc.so

when I execute line from terminal

sudo php -r "echo extension_loaded('grpc') ? 'yes' : 'no';"

it returns yes, but when I do this in php file

<?php
   echo extension_loaded('grpc') ? 'yes' : 'no';
?>

it returns no.

I edited both /etc/php/php.ini and /opt/lampp/etc/php.ini (this one I found with phpinfo() as loaded ini file). Do you guys have any ideas? I am using Manjaro if thats somehow relevant to the issue

EDIT:

It works when i run it from artisan, but when i try to run from lampp i get this error:

PHP Startup: Unable to load dynamic library 'grpc.so' (tried: /usr/lib/php/modules/grpc.so (/opt/lampp/lib/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /usr/lib/libprofiler.so.0))
2 Answers

There should be two php.ini config files in /etc/php directory

Here's the tree

/etc/php/7.3 ✹ ★ ᐅ  tree
.
├── cli
│   └── php.ini
├── fpm
│   ├── php.ini

I think the extension is only loaded on the cli specific config hence working on the terminal but not on source files

You also need to restart the php-fpm service after editing the fpm config

sudo service php7.3-fpm restart

Hope this helps

Ok, so here is the answer for generations to come, if you install grpc, and it works with a different version of php, and you really want to get it to work with lampp, you should try running command

 /opt/lampp/bin/php

and if the output is

PHP Startup: Unable to load dynamic library 'grpc.so' (tried: /usr/lib/php/modules/grpc.so (/opt/lampp/lib/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /usr/lib/libprofiler.so.0))

the solution to this issue is:

sudo cp /usr/lib/libstdc++.so.6 /opt/lampp/lib/

As far as I understand, this happens because libstdc++.so.6 in lampp folder is outdated/not complete. Anyways, that was my solution. Hope I helped somebody :)

Related