Jayant Kolhe | 300748e | 2015-02-19 11:30:40 -0800 | [diff] [blame] | 1 | |
| 2 | #Overview |
| 3 | |
| 4 | This directory contains source code for PHP implementation of gRPC layered on shared C library. |
| 5 | |
| 6 | #Status |
| 7 | |
Stanley Cheung | 76ed0cc | 2015-06-25 15:38:59 -0700 | [diff] [blame] | 8 | Alpha : Ready for early adopters |
Jayant Kolhe | 300748e | 2015-02-19 11:30:40 -0800 | [diff] [blame] | 9 | |
Stanley Cheung | dbeb1cd | 2015-08-19 08:20:06 -0700 | [diff] [blame] | 10 | ## Environment |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 11 | |
Stanley Cheung | 76ed0cc | 2015-06-25 15:38:59 -0700 | [diff] [blame] | 12 | Prerequisite: PHP 5.5 or later, `phpunit`, `pecl` |
| 13 | |
Stanley Cheung | dbeb1cd | 2015-08-19 08:20:06 -0700 | [diff] [blame] | 14 | **Linux:** |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 15 | |
Stanley Cheung | cb14eab | 2015-06-16 17:33:34 -0700 | [diff] [blame] | 16 | ```sh |
Stanley Cheung | 76ed0cc | 2015-06-25 15:38:59 -0700 | [diff] [blame] | 17 | $ sudo apt-get install php5 php5-dev phpunit php-pear |
| 18 | ``` |
| 19 | |
Stanley Cheung | dbeb1cd | 2015-08-19 08:20:06 -0700 | [diff] [blame] | 20 | **Mac OS X:** |
Stanley Cheung | 76ed0cc | 2015-06-25 15:38:59 -0700 | [diff] [blame] | 21 | |
| 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 Cheung | cb14eab | 2015-06-16 17:33:34 -0700 | [diff] [blame] | 29 | ``` |
murgatroid99 | 975a07b | 2015-02-02 14:10:42 -0800 | [diff] [blame] | 30 | |
Stanley Cheung | dbeb1cd | 2015-08-19 08:20:06 -0700 | [diff] [blame] | 31 | ## Quick Install |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 32 | |
Stanley Cheung | dbeb1cd | 2015-08-19 08:20:06 -0700 | [diff] [blame] | 33 | **Linux (Debian):** |
| 34 | |
Stanley Cheung | 581846b | 2015-09-04 12:04:17 -0700 | [diff] [blame] | 35 | Add [Debian jessie-backports][] to your `sources.list` file. Example: |
Stanley Cheung | dbeb1cd | 2015-08-19 08:20:06 -0700 | [diff] [blame] | 36 | |
| 37 | ```sh |
Stanley Cheung | 581846b | 2015-09-04 12:04:17 -0700 | [diff] [blame] | 38 | echo "deb http://http.debian.net/debian jessie-backports main" | \ |
Stanley Cheung | dbeb1cd | 2015-08-19 08:20:06 -0700 | [diff] [blame] | 39 | sudo tee -a /etc/apt/sources.list |
| 40 | ``` |
| 41 | |
Stanley Cheung | 1894f18 | 2015-08-19 16:32:39 -0700 | [diff] [blame] | 42 | Install the gRPC Debian package |
Stanley Cheung | dbeb1cd | 2015-08-19 08:20:06 -0700 | [diff] [blame] | 43 | |
| 44 | ```sh |
| 45 | sudo apt-get update |
| 46 | sudo apt-get install libgrpc-dev |
| 47 | ``` |
| 48 | |
| 49 | Install the gRPC PHP extension |
| 50 | |
| 51 | ```sh |
| 52 | sudo pecl install grpc-alpha |
| 53 | ``` |
| 54 | |
| 55 | **Mac OS X:** |
| 56 | |
| 57 | Install [homebrew][]. Example: |
| 58 | |
| 59 | ```sh |
| 60 | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" |
| 61 | ``` |
| 62 | |
| 63 | Install the gRPC core library and the PHP extension in one step |
Stanley Cheung | 3fa51a3 | 2015-06-09 16:16:42 -0700 | [diff] [blame] | 64 | |
| 65 | ```sh |
| 66 | $ curl -fsSL https://goo.gl/getgrpc | bash -s php |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 67 | ``` |
| 68 | |
Stanley Cheung | 3fa51a3 | 2015-06-09 16:16:42 -0700 | [diff] [blame] | 69 | This will download and run the [gRPC install script][] and compile the gRPC PHP extension. |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 70 | |
Stanley Cheung | dbeb1cd | 2015-08-19 08:20:06 -0700 | [diff] [blame] | 71 | |
Stanley Cheung | 3fa51a3 | 2015-06-09 16:16:42 -0700 | [diff] [blame] | 72 | ## Build from Source |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 73 | |
Stanley Cheung | 3fa51a3 | 2015-06-09 16:16:42 -0700 | [diff] [blame] | 74 | Clone this repository |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 75 | |
Stanley Cheung | 7b773e9 | 2015-08-28 09:53:16 -0700 | [diff] [blame] | 76 | ```sh |
Stanley Cheung | 3fa51a3 | 2015-06-09 16:16:42 -0700 | [diff] [blame] | 77 | $ git clone https://github.com/grpc/grpc.git |
| 78 | ``` |
mlumish | b892a27 | 2014-12-09 16:28:23 -0800 | [diff] [blame] | 79 | |
Stanley Cheung | cb14eab | 2015-06-16 17:33:34 -0700 | [diff] [blame] | 80 | Build and install the gRPC C core libraries |
Stanley Cheung | 3fa51a3 | 2015-06-09 16:16:42 -0700 | [diff] [blame] | 81 | |
| 82 | ```sh |
| 83 | $ cd grpc |
Stanley Cheung | 7b773e9 | 2015-08-28 09:53:16 -0700 | [diff] [blame] | 84 | $ git pull --recurse-submodules && git submodule update --init --recursive |
Stanley Cheung | 3fa51a3 | 2015-06-09 16:16:42 -0700 | [diff] [blame] | 85 | $ make |
| 86 | $ sudo make install |
| 87 | ``` |
| 88 | |
Stanley Cheung | 7b773e9 | 2015-08-28 09:53:16 -0700 | [diff] [blame] | 89 | 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. |
| 90 | |
| 91 | ```sh |
| 92 | $ cd grpc/third_party/protobuf |
| 93 | $ sudo make install # 'make' should have been run by core grpc |
| 94 | ``` |
| 95 | |
Stanley Cheung | cb14eab | 2015-06-16 17:33:34 -0700 | [diff] [blame] | 96 | Install the gRPC PHP extension |
| 97 | |
| 98 | ```sh |
Stanley Cheung | dbeb1cd | 2015-08-19 08:20:06 -0700 | [diff] [blame] | 99 | $ sudo pecl install grpc-alpha |
Stanley Cheung | cb14eab | 2015-06-16 17:33:34 -0700 | [diff] [blame] | 100 | ``` |
| 101 | |
| 102 | OR |
Stanley Cheung | 3fa51a3 | 2015-06-09 16:16:42 -0700 | [diff] [blame] | 103 | |
| 104 | ```sh |
| 105 | $ cd grpc/src/php/ext/grpc |
| 106 | $ phpize |
| 107 | $ ./configure |
| 108 | $ make |
| 109 | $ sudo make install |
| 110 | ``` |
| 111 | |
Stanley Cheung | e4c4738 | 2015-09-21 16:28:59 -0700 | [diff] [blame^] | 112 | Add this line to your `php.ini` file, e.g. `/etc/php5/cli/php.ini` |
| 113 | |
| 114 | ```sh |
| 115 | extension=grpc.so |
| 116 | ``` |
Stanley Cheung | 3fa51a3 | 2015-06-09 16:16:42 -0700 | [diff] [blame] | 117 | |
| 118 | Install Composer |
| 119 | |
| 120 | ```sh |
| 121 | $ cd grpc/src/php |
| 122 | $ curl -sS https://getcomposer.org/installer | php |
Stanley Cheung | e4c4738 | 2015-09-21 16:28:59 -0700 | [diff] [blame^] | 123 | $ sudo mv composer.phar /usr/local/bin/composer |
| 124 | $ composer install |
Stanley Cheung | 3fa51a3 | 2015-06-09 16:16:42 -0700 | [diff] [blame] | 125 | ``` |
| 126 | |
| 127 | ## Unit Tests |
| 128 | |
| 129 | Run unit tests |
| 130 | |
| 131 | ```sh |
| 132 | $ cd grpc/src/php |
| 133 | $ ./bin/run_tests.sh |
| 134 | ``` |
| 135 | |
| 136 | ## Generated Code Tests |
| 137 | |
| 138 | Install `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 | |
| 147 | Generate client stub code |
| 148 | |
| 149 | ```sh |
| 150 | $ cd grpc/src/php |
| 151 | $ ./bin/generate_proto_php.sh |
| 152 | ``` |
| 153 | |
| 154 | Run 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 | |
| 164 | Run the generated code tests |
| 165 | |
| 166 | ```sh |
| 167 | $ cd grpc/src/php |
| 168 | $ ./bin/run_gen_code_test.sh |
| 169 | ``` |
| 170 | |
Stanley Cheung | e4c4738 | 2015-09-21 16:28:59 -0700 | [diff] [blame^] | 171 | ## Use the gRPC PHP extension with Apache |
| 172 | |
| 173 | Install `apache2`, in addition to `php5` above |
| 174 | |
| 175 | ```sh |
| 176 | $ sudo apt-get install apache2 |
| 177 | ``` |
| 178 | |
| 179 | Add this line to your `php.ini` file, e.g. `/etc/php5/apache2/php.ini` |
| 180 | |
| 181 | ```sh |
| 182 | extension=grpc.so |
| 183 | ``` |
| 184 | |
| 185 | Restart apache |
| 186 | |
| 187 | ```sh |
| 188 | $ sudo service apache2 restart |
| 189 | ``` |
| 190 | |
| 191 | Make 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 | |
| 198 | Make sure you have run `composer install` to generate the `vendor/autoload.php` file |
| 199 | |
| 200 | ```sh |
| 201 | $ composer install |
| 202 | ``` |
| 203 | |
| 204 | Make sure you have generated the client stub `math.php` |
| 205 | |
| 206 | ```sh |
| 207 | $ ./bin/generate_proto_php.sh |
| 208 | ``` |
| 209 | |
| 210 | Copy 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 | |
| 216 | You may have to fix the first two lines to point the includes to your installation: |
| 217 | |
| 218 | ```php |
| 219 | include 'vendor/autoload.php'; |
| 220 | include 'tests/generated_code/math.php'; |
| 221 | ``` |
| 222 | |
| 223 | Connect 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 | |
| 231 | Install `nginx` and `php5-fpm`, in addition to `php5` above |
| 232 | |
| 233 | ```sh |
| 234 | $ sudo apt-get install nginx php5-fpm |
| 235 | ``` |
| 236 | |
| 237 | Add this line to your `php.ini` file, e.g. `/etc/php5/fpm/php.ini` |
| 238 | |
| 239 | ```sh |
| 240 | extension=grpc.so |
| 241 | ``` |
| 242 | |
| 243 | Uncomment the following lines in your `/etc/nginx/sites-available/default` file: |
| 244 | |
| 245 | ``` |
| 246 | location ~ \.php$ { |
| 247 | include snippets/fastcgi-php.conf; |
| 248 | fastcgi_pass unix:/var/run/php5-fpm.sock; |
| 249 | } |
| 250 | ``` |
| 251 | |
| 252 | Restart nginx and php-fpm |
| 253 | |
| 254 | ```sh |
| 255 | $ sudo service nginx restart |
| 256 | $ sudo service php5-fpm restart |
| 257 | ``` |
| 258 | |
| 259 | Make 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 | |
| 266 | Make sure you have run `composer install` to generate the `vendor/autoload.php` file |
| 267 | |
| 268 | ```sh |
| 269 | $ composer install |
| 270 | ``` |
| 271 | |
| 272 | Make sure you have generated the client stub `math.php` |
| 273 | |
| 274 | ```sh |
| 275 | $ ./bin/generate_proto_php.sh |
| 276 | ``` |
| 277 | |
| 278 | Copy 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 | |
| 284 | You may have to fix the first two lines to point the includes to your installation: |
| 285 | |
| 286 | ```php |
| 287 | include 'vendor/autoload.php'; |
| 288 | include 'tests/generated_code/math.php'; |
| 289 | ``` |
| 290 | |
| 291 | Connect 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 Cheung | 3fa51a3 | 2015-06-09 16:16:42 -0700 | [diff] [blame] | 297 | [homebrew]:http://brew.sh |
Stanley Cheung | 3fa51a3 | 2015-06-09 16:16:42 -0700 | [diff] [blame] | 298 | [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 Cheung | 581846b | 2015-09-04 12:04:17 -0700 | [diff] [blame] | 300 | [Debian jessie-backports]:http://backports.debian.org/Instructions/ |