Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 751c3f1

Browse files
meker12arhiopterecsBarny Shergoldhguthrie
authored
Update Magento Cloud Docker instructions for adding custom PHP extensions (#8145)
* [Doc] Adding new PHP extensions #155 (#7929) * Clean up instructions for adding PHP extensions - Move extension configuration attribute descriptions and examples to a separate section * Fixed markdown syntax * Fix link definitions * Fix link syntax * Apply suggestions from code review Co-authored-by: Yevhen Miroshnychenko <[email protected]> Co-authored-by: Barny Shergold <[email protected]> Co-authored-by: hguthrie <[email protected]>
1 parent 8986d63 commit 751c3f1

File tree

1 file changed

+168
-32
lines changed

1 file changed

+168
-32
lines changed

src/cloud/docker/docker-extend.md

Lines changed: 168 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ You can use the built-in extension mechanism of Docker to specify [multiple comp
1515
version: '2'
1616
services:
1717
deploy:
18-
environment:
19-
- ENABLE_SENDMAIL=false
18+
environment:
19+
- ENABLE_SENDMAIL=false
2020
```
2121
2222
1. Pass both configuration files while executing your commands. For example:
@@ -27,17 +27,16 @@ You can use the built-in extension mechanism of Docker to specify [multiple comp
2727

2828
## Specify Docker build sources
2929

30-
To test changes to images or make more extensive changes to the containers, you must build them from source. You can do this by
31-
by adding the `build:context` configuration to the `docker-compose.override.yml` file.
30+
To test changes to images or make more extensive changes to the containers, you must build them from source. You can do this by adding the `build:context` configuration to the `docker-compose.override.yml` file.
3231

3332
The following example defines the build context for the Web container. You can use the same technique to build from any of the images in the `vendor/magento/magento-cloud-docker` directory or any other Docker image, including local images that are resourced outside the project.
3433

3534
```yaml
3635
version: '2.1'
3736
services:
38-
web:
37+
web:
3938
build:
40-
context: ./vendor/magento/magento-cloud-docker/images/nginx/1.9/
39+
context: ./vendor/magento/magento-cloud-docker/images/nginx/1.9/
4140
```
4241
4342
To update the container configuration and test iteratively, use the `--force-recreate` option to refresh the container build:
@@ -48,64 +47,111 @@ docker-compose up -d --force-recreate --build
4847

4948
## Add a new version of existing service
5049

51-
In {{site.data.var.mcd}} package the available [service versions] are determined by the Docker service images configured in the {{site.data.var.mcd}} `images` directory. You can add a new service version by creating a directory for the version and adding a `Dockerfile` and other files to configure the new version.
50+
In the `{{site.data.var.mcd-package}}` package, the available [service versions] are determined by the Docker service images configured in the `images` directory. You add a new service version by creating a directory for the version and adding a `Dockerfile` and other files to configure the new version.
5251

5352
{:.procedure}
5453
To add a new service version using a `Dockerfile`:
5554

56-
1. Clone the `{{site.data.var.mcd}}` project to your local environment if necessary.
55+
1. Clone the `{{site.data.var.mcd-package}}` project to your local environment if necessary.
5756

5857
1. On the command line, change to the directory that contains the existing service version configurations.
5958

6059
```bash
61-
cd magento-cloud-docker/images/<service-name>
60+
cd magento-cloud-docker/images/<service-name>
6261
```
6362

6463
1. Create a directory for the new version.
6564

66-
1. In the new directory, add the `Dockerfile` that contains the image configuration details for the new version. Use the `Dockerfile` for an existing version as a template and add any other required configuration such as supported plugins.
65+
1. Change to the new directory.
66+
67+
1. Create a `Dockerfile` with any additional configuration details for the new version, such as supported plugins. You can use the `Dockerfile` from the previous version as a template.
6768

6869
1. Add the `docker-entrypoint.sh` and `healthcheck` files if needed.
6970

7071
1. Add any necessary `.conf` and `.ini` files for the service to the `etc` directory.
7172

72-
1. Run the following command to build the image.
73+
1. Build the image.
7374

74-
`docker build -t test/<service-name>:<service-version>`
75+
```bash
76+
docker build -t test/<service-name>:<service-version>
77+
```
7578

76-
1. Once the build succeeds, test the changes by specifying the [Docker build sources].
79+
1. After the build succeeds, test the changes by specifying the [Docker build sources].
7780

7881
## Add a new PHP extension
7982

80-
In addition to built-in extensions, you can add PHP extensions to the PHP container.
83+
You can add PHP extensions to the PHP container by adding the extension configuration to the [ExtensionResolver.php] configuration file for {{ site.data.var.mcd-prod }}.
8184

8285
{:.procedure}
8386
To add a new PHP extension:
8487

85-
1. Clone the `{{site.data.var.mcd}}` project to your local environment if necessary.
88+
1. Clone the `{{site.data.var.mcd-package}}` project to your local environment.
8689

8790
1. On the command line, navigate to the PHP directory.
8891

8992
```bash
9093
cd magento-cloud-docker/src/Compose/Php
94+
```
9195

92-
1. Open the `ExtensionResolver.php` file, define the required extension inside the `getConfig` method by specifying the extension type and dependency.
96+
1. Add one or more extensions to the `ExtensionResolver.php` file:
9397

94-
For instance the following block adds the GNUPG extension:
98+
- Open the `ExtensionResolver.php` file for editing.
9599

96-
```php?start_inline=1
97-
'gnupg' => [
98-
'>=7.0' => [
99-
self::EXTENSION_TYPE => self::EXTENSION_TYPE_PECL,
100-
self::EXTENSION_OS_DEPENDENCIES => ['libgpgme11-dev'],
101-
],],
102-
```
100+
- Specify the required extension in the `getConfig` method by specifying the extension type and dependency.
101+
102+
For example, the following block adds the `bcmath` extension:
103103

104-
The extension type can be either CORE or PECL, which are defined as `EXTENSION_TYPE_PECL` or `EXTENSION_TYPE_CORE` respectively.
104+
```php?start_inline=1
105+
public static function getConfig(): array
106+
...
107+
108+
'bcmath' => [
109+
'>=7.0' => [self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE],
110+
],
111+
...
112+
```
113+
{:.no-copy}
114+
115+
In this case, the `bcmath` PHP core extension installs from `docker-php-source` images.
116+
117+
{:.bs-callout-info}
118+
The configuration you specify depends on the location of the extension source files and method of installation. You can add PHP core extensions from the official Docker PHP images, from the PECL repository, or using an installation script. For details on the configuration attributes and format for the `getConfig` method, see [PHP extension configuration reference](#php-extension-configuration-reference).
119+
120+
1. Enable the extension by default, or by adding it to the `.magento.app.yaml` file:
121+
122+
- To enable an extension by default, add it to the `DEFAULT_PHP_EXTENSIONS` array in the `ExtensionResolver.php` file.
123+
124+
```php?start_inline=1
125+
126+
/**
127+
* Extensions which should be installed by default
128+
*/
129+
public const DEFAULT_PHP_EXTENSIONS = [
130+
'bcmath',
131+
'bz2',
132+
'calendar',
133+
'exif',
134+
'gd',
135+
'gettext',
136+
'intl',
137+
'mysqli',
138+
'pcntl',
139+
'pdo_mysql',
140+
'soap',
141+
'sockets',
142+
'sysvmsg',
143+
'sysvsem',
144+
'sysvshm',
145+
'opcache',
146+
'zip',
147+
];
148+
```
149+
150+
- If you add the extension to the `.magento.app.yaml` for your Cloud project, you must regenerate the Docker compose configuration file and restart the Docker container.
105151

106152
1. Add any required `.ini` files to the PHP FPM container configuration.
107153

108-
- On the command line, navigate to FPM image directory `magento-cloud-docker/images/php/fpm`:
154+
- On the command line, navigate to the FPM image directory `magento-cloud-docker/images/php/fpm`:
109155

110156
```bash
111157
cd ../../../images/php/fpm
@@ -131,9 +177,9 @@ To add a new PHP extension:
131177

132178
- For each `.ini` file that you add, you must add the following line to the `Dockerfile` (`magento-cloud-docker/images/php/cli/Dockerfile`):
133179

134-
```conf
135-
ADD etc/<file-name>.ini /usr/local/etc/php/conf.d/<filename>.ini
136-
```
180+
```conf
181+
ADD etc/<file-name>.ini /usr/local/etc/php/conf.d/<filename>.ini
182+
```
137183

138184
1. Generate an updated `Dockerfile` for all PHP image versions included in the {{site.data.var.mcd}} package.
139185

@@ -143,9 +189,99 @@ To add a new PHP extension:
143189

144190
1. Test the extension by specifying the [Docker build sources].
145191

146-
[multiple compose files]: https://docs.docker.com/compose/reference/overview/#specifying-multiple-compose-files
147-
[service versions]: https://devdocs.magento.com/cloud/docker/docker-containers.html#service-containers
192+
### PHP extension configuration reference
193+
194+
Use the following attributes to specify the PHP extension configuration in the `getConfig` method located in the [ExtensionResolver.php] file. The configuration you specify depends on method of installation: from the official Docker PHP images, from the PECL repository, or using an installation script.
195+
196+
| Configuration option | Description
197+
| -------------------- | ------------
198+
| PHP version constraint | Specifies the extension versions to install. If different versions have different installation requirements, you must add the configuration for each version.
199+
| `EXTENSION_TYPE_CORE` | Extension that can be installed from a `docker-php-source` images.
200+
| `EXTENSION_TYPE_PECL` | Extensions that can be installed from the [PECL] repository.
201+
| `EXTENSION_TYPE_INSTALLATION_SCRIPT` | For extensions that install using a command sequence.
202+
| `EXTENSION_TYPE` | Specifies whether the extension installed from the Docker PHP images, the PECL repository, or using an installation script. Valid values: `EXTENSION_TYPE_CORE`, `EXTENSION_TYPE_PECL`, or `EXTENSION_TYPE_INSTALLATION_SCRIPT`<br>
203+
`EXTENSION_OS_DEPENDENCIES` | For PHP core or PECL extensions, specifies Linux package dependencies. These packages install in the order listed before installing the extension.
204+
`EXTENSION_CONFIGURE_OPTIONS` | For PHP core extensions, specifies any configuration options to apply when Docker configures the PHP extension using the `docker-php-ext-configure` command.
205+
`EXTENSION_PACKAGE_NAME` | Specifies the extension package name. This value is used to generate the installation command.
206+
`EXTENSION_INSTALLATION_SCRIPT` | For extension type `EXTENSION_TYPE_INSTALLATION_SCRIPT`, specifies the Bash script to install the extension.
207+
208+
{:.bs-callout-info}
209+
For more information about extension types and extension installation, see _How to install more PHP extensions_ section of the [PHP, Docker Official Images] page in Docker Hub.
210+
211+
#### Example: Core extension configuration
212+
213+
The following example shows the configuration for adding the PHP core extension `gd` in the `ExtensionResolver.php` file.
214+
215+
```php?start_inline=1
216+
public static function getConfig(): array
217+
...
218+
'gd' => [
219+
'>=7.0 <=7.3' => [
220+
self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE,
221+
self::EXTENSION_OS_DEPENDENCIES => ['libjpeg62-turbo-dev', 'libpng-dev', 'libfreetype6-dev'],
222+
self::EXTENSION_CONFIGURE_OPTIONS => [
223+
'--with-freetype-dir=/usr/include/',
224+
'--with-jpeg-dir=/usr/include/'
225+
],
226+
],
227+
'>=7.4' => [
228+
self::EXTENSION_TYPE => self::EXTENSION_TYPE_CORE,
229+
self::EXTENSION_OS_DEPENDENCIES => ['libjpeg62-turbo-dev', 'libpng-dev', 'libfreetype6-dev'],
230+
self::EXTENSION_CONFIGURE_OPTIONS => [
231+
'--with-freetype=/usr/include/',
232+
'--with-jpeg=/usr/include/'
233+
],
234+
],
235+
236+
],
237+
...
238+
```
239+
240+
#### Example: PECL extension configuration
241+
242+
The following example shows the configuration for adding the `gnupg` extension from the PECL repository.
243+
244+
```php?start_inline=1
245+
public static function getConfig(): array
246+
...
247+
'gnupg' => [
248+
'>=7.0' => [
249+
self::EXTENSION_TYPE => self::EXTENSION_TYPE_PECL,
250+
self::EXTENSION_OS_DEPENDENCIES => ['libgpgme11-dev'],
251+
],
252+
],
253+
...
254+
```
255+
256+
#### Example: Configuration for extension installed using a script
257+
258+
The following example shows the configuration for installing the `ioncube` extension using an installation script.
259+
260+
```php?start_inline=1
261+
public static function getConfig(): array
262+
...
263+
264+
'ioncube' => [
265+
'>=7.0 <=7.3' => [
266+
self::EXTENSION_TYPE => self::EXTENSION_TYPE_INSTALLATION_SCRIPT,
267+
self::EXTENSION_INSTALLATION_SCRIPT => <<< BASH
268+
cd /tmp
269+
curl -O https://downloads.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz
270+
tar zxvf ioncube_loaders_lin_x86-64.tar.gz
271+
export PHP_VERSION=$(php -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;")
272+
export PHP_EXT_DIR=$(php-config --extension-dir)
273+
cp "./ioncube/ioncube_loader_lin_\${PHP_VERSION}.so" "\${PHP_EXT_DIR}/ioncube.so"
274+
rm -rf ./ioncube
275+
rm ioncube_loaders_lin_x86-64.tar.gz
276+
BASH
277+
],
278+
],
279+
...
280+
```
281+
148282
[Docker build sources]: https://devdocs.magento.com/cloud/docker/docker-extend.html#specify-docker-build-sources
283+
[ExtensionResolver.php]: https://github.com/magento/magento-cloud-docker/tree/develop/src/Compose/Php
284+
[PECL]: https://pecl.php.net/
285+
[PHP, Docker Official Images]: https://hub.docker.com/_/php
149286
[multiple compose files]: https://docs.docker.com/compose/reference/overview/#specifying-multiple-compose-files
150287
[service versions]: https://devdocs.magento.com/cloud/docker/docker-containers.html#service-containers
151-
[Docker build sources]: https://devdocs.magento.com/cloud/docker/docker-extend.html#specify-docker-build-sources

0 commit comments

Comments
 (0)