Configuring PHP
PHP configuration is stored within the cma.js
file:
Changing the PHP version
The default version of PHP for your project is defined by the Magento version according to Magento System Requirements for Magento 2.4 and Magento 2.3.
PHP to Magento version mapping will look like this:
PHP 8.2 - Magento 2.4.7 (+ patches)
PHP 8.1 - Magento 2.4.4, 2.4.5, 2.4.6 (+ patches)
PHP 7.4 - Magento 2.3.7, 2.4.0, 2.4.1, 2.4.2, 2.4.3 (+ patches)
PHP 7.3 - Magento 2.3.3, 2.3.4, 2.3.5, 2.3.6 (+ patches)
PHP 7.2 - Magento 2.2.10, 2.3.0, 2.3.1, 2.3.2 (+ patches)
To change the PHP version, select the PHP version from the PHP Images section and then the PHP version with Magento extensions.
For example, you have Magento 2.4.3 project and you want to use PHP 8.1. The configuration file cma.js
will look accordingly:
Note that we are changing both baseImage and debugImage properties!
After changing the configuration, restart the app to install the new PHP version:
And validate the new PHP installation through the CLI:
Also, the PHP version will be printed during start
command execution:
Installing PHP extensions
Some extensions have a separate package that can be integrated into cma.js
like ionCube extension!
By default, only the extensions that are required by Magento are installed. If you need to install any additional extensions, cma.js will have to be changed accordingly:
All of this might look complicated, but this object describes the following information for magento-scripts:
PHP Extension name. Defined in
configuration.php.extensions
as a key for configuration object.Dependencies required by the extension. Defined in
configuration.php.extensions[name].dependencies
as an array of strings. Optional.Command to install the extension inside the project image. Defined in
configuration.php.extensions[name].command
as a string or as a synchronous function that returns a string or asynchronous function that returns a string. Optional.
The current example defines that memcached
extension requires 2 dependencies to be installed from apk repository: libmemcached-dev
and zlib-dev
and a command to install the extension itself.
The command consists of 4 steps:
Installing build dependencies for PECL extension.
Installing the extension itself from PECL.
Enabling installed extension
Removing build dependencies to save space inside the project image.
The command is written in one line because it will use one RUN instruction inside Dockerfile.
Dependencies for extensions are recommended to move to the separate dependencies
property because they will be installed together with other dependencies from other extensions in one RUN instruction inside Dockerfile.
You can also install extensions from the docker-php-ext-install project. The same utility is shipped in official PHP images and if you will not define any settings in PHP extension configuration, CMA will install the extension using docker-php-ext-install <extension name>
command. Example:
This will install a PHP calendar extension.
To retrieve all extensions that docker-php-ext-install
utility can install you can run the following command inside CLI: exec php docker-php-ext-install
After you made your changes restart the app for changes to take effect:
And validate newly installed extensions through the CLI:
Last updated