blob: f474ff7cabba626fb4eb969afc2cdecafc421761 [file] [log] [blame] [view]
Jayant Kolhe300748e2015-02-19 11:30:40 -08001
2#Overview
3
4This directory contains source code for PHP implementation of gRPC layered on shared C library.
5
6#Status
7
Stanley Cheung76ed0cc2015-06-25 15:38:59 -07008Alpha : Ready for early adopters
Jayant Kolhe300748e2015-02-19 11:30:40 -08009
Stanley Cheungdbeb1cd2015-08-19 08:20:06 -070010## Environment
mlumishb892a272014-12-09 16:28:23 -080011
Stanley Cheung76ed0cc2015-06-25 15:38:59 -070012Prerequisite: PHP 5.5 or later, `phpunit`, `pecl`
13
Stanley Cheungdbeb1cd2015-08-19 08:20:06 -070014**Linux:**
mlumishb892a272014-12-09 16:28:23 -080015
Stanley Cheungcb14eab2015-06-16 17:33:34 -070016```sh
Stanley Cheung76ed0cc2015-06-25 15:38:59 -070017$ sudo apt-get install php5 php5-dev phpunit php-pear
18```
19
Stanley Cheungdbeb1cd2015-08-19 08:20:06 -070020**Mac OS X:**
Stanley Cheung76ed0cc2015-06-25 15:38:59 -070021
22```sh
23$ curl https://phar.phpunit.de/phpunit.phar -o phpunit.phar
24$ chmod +x phpunit.phar
25$ sudo mv phpunit.phar /usr/local/bin/phpunit
26
27$ curl -O http://pear.php.net/go-pear.phar
28$ sudo php -d detect_unicode=0 go-pear.phar
Stanley Cheungcb14eab2015-06-16 17:33:34 -070029```
murgatroid99975a07b2015-02-02 14:10:42 -080030
Stanley Cheungdbeb1cd2015-08-19 08:20:06 -070031## Quick Install
mlumishb892a272014-12-09 16:28:23 -080032
Stanley Cheungdbeb1cd2015-08-19 08:20:06 -070033**Linux (Debian):**
34
Stanley Cheung581846b2015-09-04 12:04:17 -070035Add [Debian jessie-backports][] to your `sources.list` file. Example:
Stanley Cheungdbeb1cd2015-08-19 08:20:06 -070036
37```sh
Stanley Cheung581846b2015-09-04 12:04:17 -070038echo "deb http://http.debian.net/debian jessie-backports main" | \
Stanley Cheungdbeb1cd2015-08-19 08:20:06 -070039sudo tee -a /etc/apt/sources.list
40```
41
Stanley Cheung1894f182015-08-19 16:32:39 -070042Install the gRPC Debian package
Stanley Cheungdbeb1cd2015-08-19 08:20:06 -070043
44```sh
45sudo apt-get update
46sudo apt-get install libgrpc-dev
47```
48
49Install the gRPC PHP extension
50
51```sh
52sudo pecl install grpc-alpha
53```
54
55**Mac OS X:**
56
57Install [homebrew][]. Example:
58
59```sh
60ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
61```
62
63Install the gRPC core library and the PHP extension in one step
Stanley Cheung3fa51a32015-06-09 16:16:42 -070064
65```sh
66$ curl -fsSL https://goo.gl/getgrpc | bash -s php
mlumishb892a272014-12-09 16:28:23 -080067```
68
Stanley Cheung3fa51a32015-06-09 16:16:42 -070069This will download and run the [gRPC install script][] and compile the gRPC PHP extension.
mlumishb892a272014-12-09 16:28:23 -080070
Stanley Cheungdbeb1cd2015-08-19 08:20:06 -070071
Stanley Cheung3fa51a32015-06-09 16:16:42 -070072## Build from Source
mlumishb892a272014-12-09 16:28:23 -080073
Stanley Cheung3fa51a32015-06-09 16:16:42 -070074Clone this repository
mlumishb892a272014-12-09 16:28:23 -080075
Stanley Cheung7b773e92015-08-28 09:53:16 -070076```sh
Stanley Cheung3fa51a32015-06-09 16:16:42 -070077$ git clone https://github.com/grpc/grpc.git
78```
mlumishb892a272014-12-09 16:28:23 -080079
Stanley Cheungcb14eab2015-06-16 17:33:34 -070080Build and install the gRPC C core libraries
Stanley Cheung3fa51a32015-06-09 16:16:42 -070081
82```sh
83$ cd grpc
Stanley Cheung7b773e92015-08-28 09:53:16 -070084$ git pull --recurse-submodules && git submodule update --init --recursive
Stanley Cheung3fa51a32015-06-09 16:16:42 -070085$ make
86$ sudo make install
87```
88
Stanley Cheung7b773e92015-08-28 09:53:16 -070089Note: 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.
90
91```sh
92$ cd grpc/third_party/protobuf
93$ sudo make install # 'make' should have been run by core grpc
94```
95
Stanley Cheungcb14eab2015-06-16 17:33:34 -070096Install the gRPC PHP extension
97
98```sh
Stanley Cheungdbeb1cd2015-08-19 08:20:06 -070099$ sudo pecl install grpc-alpha
Stanley Cheungcb14eab2015-06-16 17:33:34 -0700100```
101
102OR
Stanley Cheung3fa51a32015-06-09 16:16:42 -0700103
104```sh
105$ cd grpc/src/php/ext/grpc
106$ phpize
107$ ./configure
108$ make
109$ sudo make install
110```
111
Stanley Cheunge4c47382015-09-21 16:28:59 -0700112Add this line to your `php.ini` file, e.g. `/etc/php5/cli/php.ini`
113
114```sh
115extension=grpc.so
116```
Stanley Cheung3fa51a32015-06-09 16:16:42 -0700117
118Install Composer
119
120```sh
121$ cd grpc/src/php
122$ curl -sS https://getcomposer.org/installer | php
Stanley Cheunge4c47382015-09-21 16:28:59 -0700123$ sudo mv composer.phar /usr/local/bin/composer
124$ composer install
Stanley Cheung3fa51a32015-06-09 16:16:42 -0700125```
126
127## Unit Tests
128
129Run unit tests
130
131```sh
132$ cd grpc/src/php
133$ ./bin/run_tests.sh
134```
135
136## Generated Code Tests
137
138Install `protoc-gen-php`
139
140```sh
141$ cd grpc/src/php/vendor/datto/protobuf-php
142$ gem install rake ronn
143$ rake pear:package version=1.0
144$ sudo pear install Protobuf-1.0.tgz
145```
146
147Generate client stub code
148
149```sh
150$ cd grpc/src/php
151$ ./bin/generate_proto_php.sh
152```
153
154Run a local server serving the math services
155
156 - Please see [Node][] on how to run an example server
157
158```sh
159$ cd grpc/src/node
160$ npm install
161$ nodejs examples/math_server.js
162```
163
164Run the generated code tests
165
166```sh
167$ cd grpc/src/php
168$ ./bin/run_gen_code_test.sh
169```
170
Stanley Cheunge4c47382015-09-21 16:28:59 -0700171## Use the gRPC PHP extension with Apache
172
173Install `apache2`, in addition to `php5` above
174
175```sh
176$ sudo apt-get install apache2
177```
178
179Add this line to your `php.ini` file, e.g. `/etc/php5/apache2/php.ini`
180
181```sh
182extension=grpc.so
183```
184
185Restart apache
186
187```sh
188$ sudo service apache2 restart
189```
190
191Make sure the Node math server is still running, as above.
192
193```sh
194$ cd grpc/src/node
195$ nodejs examples/math_server.js
196```
197
198Make sure you have run `composer install` to generate the `vendor/autoload.php` file
199
200```sh
201$ composer install
202```
203
204Make sure you have generated the client stub `math.php`
205
206```sh
207$ ./bin/generate_proto_php.sh
208```
209
210Copy the `math_client.php` file into your Apache document root, e.g.
211
212```sh
213$ cp tests/generated_code/math_client.php /var/www/html
214```
215
216You may have to fix the first two lines to point the includes to your installation:
217
218```php
219include 'vendor/autoload.php';
220include 'tests/generated_code/math.php';
221```
222
223Connect to `localhost/math_client.php` in your browser, or run this from command line:
224
225```sh
226$ curl localhost/math_client.php
227```
228
229## Use the gRPC PHP extension with Nginx/PHP-FPM
230
231Install `nginx` and `php5-fpm`, in addition to `php5` above
232
233```sh
234$ sudo apt-get install nginx php5-fpm
235```
236
237Add this line to your `php.ini` file, e.g. `/etc/php5/fpm/php.ini`
238
239```sh
240extension=grpc.so
241```
242
243Uncomment the following lines in your `/etc/nginx/sites-available/default` file:
244
245```
246location ~ \.php$ {
247 include snippets/fastcgi-php.conf;
248 fastcgi_pass unix:/var/run/php5-fpm.sock;
249}
250```
251
252Restart nginx and php-fpm
253
254```sh
255$ sudo service nginx restart
256$ sudo service php5-fpm restart
257```
258
259Make sure the Node math server is still running, as above.
260
261```sh
262$ cd grpc/src/node
263$ nodejs examples/math_server.js
264```
265
266Make sure you have run `composer install` to generate the `vendor/autoload.php` file
267
268```sh
269$ composer install
270```
271
272Make sure you have generated the client stub `math.php`
273
274```sh
275$ ./bin/generate_proto_php.sh
276```
277
278Copy the `math_client.php` file into your Nginx document root, e.g.
279
280```sh
281$ cp tests/generated_code/math_client.php /var/www/html
282```
283
284You may have to fix the first two lines to point the includes to your installation:
285
286```php
287include 'vendor/autoload.php';
288include 'tests/generated_code/math.php';
289```
290
291Connect to `localhost/math_client.php` in your browser, or run this from command line:
292
293```sh
294$ curl localhost/math_client.php
295```
296
Stanley Cheung3fa51a32015-06-09 16:16:42 -0700297[homebrew]:http://brew.sh
Stanley Cheung3fa51a32015-06-09 16:16:42 -0700298[gRPC install script]:https://raw.githubusercontent.com/grpc/homebrew-grpc/master/scripts/install
299[Node]:https://github.com/grpc/grpc/tree/master/src/node/examples
Stanley Cheung581846b2015-09-04 12:04:17 -0700300[Debian jessie-backports]:http://backports.debian.org/Instructions/