# Configuring PHP

PHP configuration is stored within the `cma.js` file:

```javascript
module.exports = {
    magento: {
        first_name: 'Scandiweb',
        last_name: 'Developer',
        email: 'developer@scandipwa.com',
        user: 'admin',
        password: 'scandipwa123',
        adminuri: 'admin',
        mode: 'developer',
    },
    configuration: {
        php: {
            // PHP configuration goes here
        }
    }
};

```

## 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](https://experienceleague.adobe.com/docs/commerce-operations/installation-guide/system-requirements.html) and [Magento 2.3](https://devdocs.magento.com/guides/v2.3/install-gde/system-requirements.html).

PHP to Magento version mapping will look like this:

* [PHP 8.4](https://docs.create-magento-app.com/container-images/php-images/php-8.4) - Available for Magento 2.4.8
* [PHP 8.3](https://docs.create-magento-app.com/container-images/php-images/php-8.3) - Magento 2.4.8
* [PHP 8.2 ](https://docs.create-magento-app.com/container-images/php-images/php-8.2)- Magento 2.4.7 (+ patches)
* [PHP 8.1 ](https://docs.create-magento-app.com/container-images/php-images/php-8.1)- Magento 2.4.4, 2.4.5, 2.4.6 (+ patches)
* [PHP 7.4](https://docs.create-magento-app.com/container-images/php-images/php-7.4) - Magento 2.3.7, 2.4.0, 2.4.1, 2.4.2, 2.4.3 (+ patches)
* [PHP 7.3](https://docs.create-magento-app.com/container-images/php-images/php-7.3) - Magento 2.3.3, 2.3.4, 2.3.5, 2.3.6 (+ patches)
* [PHP 7.2](https://docs.create-magento-app.com/container-images/php-images/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](https://docs.create-magento-app.com/container-images/php-images) section and then the PHP version with Magento extensions.&#x20;

For example, you have Magento 2.4.8 project and you want to use [PHP 8.4](https://docs.create-magento-app.com/container-images/php-images/php-8.4). The configuration file `cma.js` will look accordingly:

{% code title="cma.js" %}

```javascript
/** @type {import('@scandipwa/magento-scripts').CMAConfiguration} */
module.exports = {
    // ... other configurations
    configuration: {
        php: {
            baseImage: 'ghcr.io/scandipwa/create-magento-app:php-8.4-magento-2.4'
        }
    }
};
```

{% endcode %}

After changing the configuration, restart the app to install the new PHP version:

```javascript
yarn start
```

And validate the new PHP installation through the CLI:

<figure><img src="https://1705439005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MOVnS5lKxiIvOL9no4d%2Fuploads%2F2SISvKWbfgjL1yK8i87j%2FScreenshot_20250513_152735.png?alt=media&#x26;token=c083354e-b1c9-4e7d-a66d-d1ebbf5fd525" alt=""><figcaption></figcaption></figure>

Also, the PHP version will be printed during `start` command execution:

<figure><img src="https://1705439005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MOVnS5lKxiIvOL9no4d%2Fuploads%2Fk1pCN4xDN0UXZ37mMx2V%2FScreenshot_20250513_152829.png?alt=media&#x26;token=2ad3b264-64e8-44f3-9abb-ed0553b13c30" alt=""><figcaption></figcaption></figure>

## Installing PHP extensions

{% hint style="success" %}
Some extensions have a separate package that can be integrated into `cma.js` like [ionCube extension](https://docs.create-magento-app.com/scripts-extensions/php-extensions/deprecated-ioncube-extension)!
{% endhint %}

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.

### Simple extension installation

If the extension you want to install is available in[ Supported Extension list](https://github.com/mlocati/docker-php-extension-installer?tab=readme-ov-file#supported-php-extensions) in the [docker-php-extension-installer](https://github.com/mlocati/docker-php-extension-installer) project, then installation is pretty simple:

{% code title="cma.js" %}

```javascript
/** @type {import('@scandipwa/magento-scripts').CMAConfiguration} */
module.exports = {
    // ... other configurations
    configuration: {
        php: {
            extensions: {
                calendar: {}
            }
        }
    }
};
```

{% endcode %}

This will install a PHP [calendar](https://www.php.net/manual/en/book.calendar.php) extension. Restart the app for changes to take effect:&#x20;

```javascript
yarn start
```

And validate newly installed extensions through the CLI:

```bash
yarn cli
bash$ php -m | grep calendar
calendar
```

### Complex extension installation

If extension is not available in the Supported Extension list, then you can define your custom command to install the extension from [pecl](https://pecl.php.net/).

{% code title="cma.js" %}

```javascript
/** @type {import('@scandipwa/magento-scripts').CMAConfiguration} */
module.exports = {
    // ... other configurations
    configuration: {
        php: {
            extensions: {
                memcached: {
                    command: `apk add --no-cache --virtual .build-deps \\$PHPIZE_DEPS \
                    && pecl install memcached \
                    && docker-php-ext-enable memcached \
                    && apk del -f .build-deps`,
                    dependencies: [
                        'libevent-dev',
                        'libmemcached-dev',
                        'zlib-dev'
                    ]
                }
            }
        }
    }
};

```

{% endcode %}

All of this might look complicated, but this object describes the following information for **magento-scripts**:

1. PHP Extension name. Defined in `configuration.php.extensions` as a key for configuration object.
2. 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.
3. Dependencies required by the extension. Defined in `configuration.php.extensions[name].dependencies` as an array of strings. Optional.

The current example defines that `memcached` extension requires 2 dependencies to be installed from [apk repository](https://pkgs.alpinelinux.org/packages): `libmemcached-dev` and `zlib-dev` and a command to install the extension itself.\
The command consists of 4 steps:

1. Installing build dependencies for [PECL](https://pecl.php.net/) extension.
2. Installing the extension itself from [PECL](https://pecl.php.net/).
3. Enabling installed extension
4. Removing build dependencies to save space inside the project image.

The command is written in one line because it will use one [RUN](https://docs.docker.com/engine/reference/builder/#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.

After you made your changes restart the app for changes to take effect:

```javascript
yarn start
```

And validate newly installed extensions through the CLI:

```bash
yarn cli
bash$ php -m | grep memcached
memcached
```
