Skip to content

Commit b08bc07

Browse files
authored
chore: add README to extension example (GoogleCloudPlatform#1652)
1 parent 3674924 commit b08bc07

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Custom Extensions for App Engine Standard
2+
3+
This sample shows how to compile custom extensions for PHP that aren't already included in
4+
the [activated extensions](https://cloud.google.com/appengine/docs/standard/php-gen2/runtime#enabled_extensions)
5+
or [dynamically loadable extensions](https://cloud.google.com/appengine/docs/standard/php-gen2/runtime#dynamically_loadable_extensions).
6+
7+
This can be useful for activating extensions such as [sqlsrv](https://pecl.php.net/package/sqlsrv) which are not (yet) supported
8+
by this runtime.
9+
10+
## Steps to compiling and activating custom extensions
11+
12+
1. Put the custom extension code in a directory in your project, so it gets uploaded with
13+
the rest of your application. In this example we use the directory named `ext`.
14+
15+
2. Put the commands to compile the extension and move it into the `vendor` directory
16+
in your `composer.json`.
17+
18+
```json
19+
{
20+
"scripts": {
21+
"post-autoload-dump": [
22+
"cd ext && phpize --clean && phpize && ./configure && make",
23+
"cp ext/modules/sqlsrv.so vendor/"
24+
]
25+
}
26+
}
27+
```
28+
**NOTE**: Moving the extension into the `vendor` directory ensures the file is cached. This
29+
means if you modify the ext directory, you'll need to run gcloud app deploy with the
30+
`--no-cache argument` to rebuild it.
31+
32+
3. Activate the extension in your `php.ini`:
33+
```ini
34+
# php.ini
35+
extension=/workspace/vendor/my_custom_extension.so
36+
```
37+
38+
4. Deploy your application as usual with `gcloud app deploy`. In this example, we use `index.php`
39+
to print `phpinfo()` so we can see that the extension has been activated.

0 commit comments

Comments
 (0)