This will compile and install the gRPC PHP extension into the standard PHP extension directory. You should be able to run the [unit tests](#unit-tests), with the PHP extension installed.
To run tests with generated stub code from `.proto` files, you will need the `composer`, `protoc` and `protoc-gen-php` binaries additionally. See sections [below](#generated-code-tests).
## Build from Source
### gRPC C core library
Clone this repository
```sh
$ git clone https://github.com/grpc/grpc.git
```
Build and install the gRPC C core libraries
Build and install the gRPC C core library
```sh
$ cd grpc
@ -56,20 +70,15 @@ $ make
$ sudo make install
```
Note: you may encounter a warning about the Protobuf compiler `protoc` 3.0.0+ not being installed. The following might help, and will be useful later on when we need to compile the `protoc-gen-php` tool.
### gRPC PHP extension
```sh
$ cd grpc/third_party/protobuf
$ sudo make install # 'make' should have been run by core grpc
```
Install the gRPC PHP extension
Install the gRPC PHP extension from PECL
```sh
$ sudo pecl install grpc-beta
```
OR
Or, compile from source
```sh
$ cd grpc/src/php/ext/grpc
@ -79,58 +88,96 @@ $ make
$ sudo make install
```
### Update php.ini
Add this line to your `php.ini` file, e.g. `/etc/php5/cli/php.ini`
You need the install the protobuf compiler, `protoc`, 3.0.0+.
If you had compiled the gRPC C core library from source above, the `protoc` binary should have been installed as well. In the case it wasn't, you can run the following commands to install it.
```sh
$ cd grpc/src/php
$ ./bin/run_tests.sh
$ cd grpc/third_party/protobuf
$ sudo make install # 'make' should have been run by core grpc
```
## Generated Code Tests
Or you can download a `protoc` binaries from [here](https://github.com/google/protobuf/releases).
Install `protoc-gen-php`
### PHP protobuf compiler
You need to install `protoc-gen-php`, so that you can generate stub classes `.php` files from service definition `.proto` files.
```sh
$ cd grpc/src/php/vendor/datto/protobuf-php
$ cd grpc/src/php/vendor/datto/protobuf-php # if you had run `composer install` in the previous step
OR
$ git clone https://github.com/stanley-cheung/Protobuf-PHP # clone from github repo
$ gem install rake ronn
$ rake pear:package version=1.0
$ sudo pear install Protobuf-1.0.tgz
```
Generate client stub code
### Client Stub
Generate client stub classes from `.proto` files
```sh
$ cd grpc/src/php
$ ./bin/generate_proto_php.sh
```
Run a local server serving the math services
### Run test server
- Please see [Node][] on how to run an example server
Run a local server serving the math services. Please see [Node][] on how to run an example server
```sh
$ cd grpc/src/node
$ cd grpc
$ npm install
$ nodejs examples/math_server.js
$ nodejs src/node/test/math/math_server.js
```
### Run test client
Run the generated code tests
```sh
@ -161,13 +208,15 @@ $ sudo service apache2 restart
Make sure the Node math server is still running, as above.
```sh
$ cd grpc/src/node
$ nodejs examples/math_server.js
$ cd grpc
$ npm install
$ nodejs src/node/test/math/math_server.js
```
Make sure you have run `composer install` to generate the `vendor/autoload.php` file
```sh
$ cd grpc/src/php
$ composer install
```
@ -229,13 +278,15 @@ $ sudo service php5-fpm restart
Make sure the Node math server is still running, as above.
```sh
$ cd grpc/src/node
$ nodejs examples/math_server.js
$ cd grpc
$ npm install
$ nodejs src/node/test/math/math_server.js
```
Make sure you have run `composer install` to generate the `vendor/autoload.php` file