Installing gRPC for localhost

…衆ロ難τιáo~ 提交于 2019-12-11 02:26:17

问题


I'm working with PHP library of Google Cloud Firestore, it requires me to install and enable the gRPC extension.. I've read the guide which says

Windows users can download and enable DLLs from PECL. Support for Windows is experimental

In the PECL site I can see many links to tgz and DLL files but without any explanation of how to use or activate them in the XAMPP as a localhost


回答1:


With the help of this link.. I found that these steps will activate gRPC

  1. From PECL site.. choose DLL of the latest stable release
  2. According to the PHP version you have .. choose Non Thread Safe (NTS) x86
  3. Download the ZIP file then extract its contents
  4. Copy the php_grpc.dll file to the extensions folder in XAMPP (you can find the path in php.ini) .. in my case it was extension_dir="C:\xampp\php\ext"
  5. Enable the extension in your php.ini file by adding extension=php_grpc.dll
  6. Restart XAMPP and the extension will be activated as showed in phpinfo()




回答2:


For windows modern Xampp have as syntax in php.ini extension=php_grpc

no need .dll as extension in trail




回答3:


Please download grpc extension zip from here

https://windows.php.net/downloads/pecl/releases/grpc/1.10.0/

accorging to your php version (My PHP version is 7.2.6 and x86 architecture xampp) I downloaded php_grpc-1.10.0-7.2-ts-vc15-x86.zip

after downloading extract zip file copy php_grpc.dll in e.g C:\xampp\php\ext folder

open php.ini under Dynamic extentions add extension=grpc

restart your apache server for checking open up cmd and type php -m it will show you all the extension enabled.




回答4:


My PHP version is 7.2.

I downloaded and uploaded php_grpc.dll inside my xampp/php/ext/php_grpc.dll and added a code in php.init, extension=grpc (on latest version you don't need to add php_ and .dll), then I restart Xampp

Now terminal says

PHP Warning: PHP Startup: Unable to load dynamic library 'grpc' (tried: E:\xampp\php\ext\grpc (The specified module could not be found.), E:\xampp\php\ext\php_grpc.dll (The specified module could not be found.)) in Unknown on line 0

Your requirements could not be resolved to an installable set of packages.

Problem 1 - google/cloud-firestore v1.6.2 requires ext-grpc * -> the requested PHP extension grpc is missing from your system. - google/cloud-firestore v1.6.1 requires ext-grpc * -> the requested PHP extension grpc is missing from your system. - google/cloud-firestore v1.6.0 requires ext-grpc * -> the requested PHP extension grpc is missing from your system. - Installation request for google/cloud-firestore ^1.6 -> satisfiable by google/cloud-firestore[v1.6.0, v1.6.1, v1.6.2].

To enable extensions, verify that they are enabled in your .ini files: - E:\xampp\php\php.ini You can also run php --ini inside terminal to see which files are used by PHP in CLI mode.

Installation failed, reverting ./composer.json to its original content.




回答5:


Windows 10 | PHP 7.1

I tried to debug this for 4 hours and could not find the right solution. I later on realized that besides the grpc extension, there were some other extensions also like oci which threw the same error when I tried to uncomment those (while keeping grpc commented) and running any php command like php --ini

On some other forum I read that a user had to manually install PHP using windows installer and then install DLL. I thought I'll try that but I could not find an MSI so I downloaded the latest PHP zip installer from https://windows.php.net/download/ I chose the x64 version for php 7.1.

Please note that I did not install this downloaded PHP but I noticed it had a php7.dll I had used dependency walker from http://www.dependencywalker.com/ to check the dependencies of the php_grpc.dll and found php7.dll as a dependency.

So what I did was to copy both PHP7.dll and php_grpc.dll to system32 and then I tried to install that DLL. I ran a command prompt as Admin and navigated to C:\windows\system32 and executed the command regsvr32 php_grpc.dll (Please note that this does not work without PHP7.dll being present in the same folder - or at least it did not work for me). Upon execution, I got a message that the DLL was loaded but entry point was not found. At this time when I executed php --ini again (I also had php_grpc.dll loaded to ext folder under the XAMPP php folder) I got a new error finally which said that the module being loaded was Non thread safe (NTS) whereas PHP was TS (Thread Safe). So I went to PECL, downloaded the TS version of the grpc plugin for PHP7.1 and pasted the dll file to both system32 and also the ext folder. I ran the regsvr32 /U php_grpc.dll command which uninstalls and reinstalls the DLL i believe (I am not sure if this step made any difference but I am mentioning it here because I had performed this step before calling php --ini)

After this, finally php --ini ran without any issues. I was able to use the composer command to successfully download the dependencies for cloud-firestore. It was a waste of 4 precious hours but I hope this helps someone else.

NOTE: Instead of downloading from PECL, I downloaded the grpc zip from https://windows.php.net/downloads/pecl/releases/grpc/

I don't know if this is different but it was the link mentioned on the installation site for Windows installation of PHP. Also someone else has that link here. I took the latest build which was 1.24.0 at the time of this post. And I chose the Thread Safe Version.

The reason I chose the thread safe version is because of the error that I received of version mismatch. You can also check your version by executing "php -i" in console which returns same info as phpinfo(); Copy and paste the output in some text editor and search for PHP Extension Build. below is what I saw

PHP Extension Build => API20160303,TS,VC14

Note, it is TS aka thread safe. So unlike other posts on the internet where folks downloaded non thread safe version of grpc, I downloaded threadsafe and it worked.



来源:https://stackoverflow.com/questions/50222772/installing-grpc-for-localhost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!