Cover of the book Symfony 5: The Fast Track

Symfony 5: The Fast Track is the best book to learn modern Symfony development, from zero to production. +300 pages in full color showing how to combine Symfony with Docker, APIs, queues & async tasks, Webpack, Single-Page Applications, etc.

Buy printed version

SymfonyCloud: Installing PHP extensions

When deploying an application on SymfonyCloud, you can specify which PHP extensions your application needs:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# .symfony.cloud.yaml
type: php:7.4

runtime:
    extensions:
        - blackfire
        - xsl
        - amqp
        - pdo_pgsql
        - apcu
        - mbstring
        - sodium
        - ctype
        - iconv

Depending on the version of PHP, you might get different versions of each extension. But you will get the version provided by SymfonyCloud and that only works for supported extensions.

But what if you need a specific version of a PHP extension? Or what if you want to install an extension that is not pre-compiled on SymfonyCloud?

Let’s take an example. On PHP 7.4, we have decided to not provide the Redis extension anymore because of some API breaks. To avoid any issues, you should now install the version that your application can support:

1
2
3
variables:
    php-ext:
        redis: 5.3.1

When using this configuration, the extension will be downloaded and compiled at built time.

You can also use the php-ext-install script in your build configuration:

1
2
3
4
5
6
7
8
9
hooks:
    build: |
        set -x -e

        curl -s http://get.symfony.com/cloud/configurator | (>&2 bash)
        (>&2
            php-ext-install redis 5.3.1
            symfony-build
        )

This script is also very useful when you want to install a PHP extension that is not available on PECL or if you want to test a specific branch of an extension repository:

1
php-ext-install redis https://github.com/phpredis/phpredis.git some-bug-fix-branch-name

Learn more in the docs.

This is a great way to control extension versions and to depend on any extension you might need.

Enjoy!

Comments

Wouldn't be better to load the extensions from composer.json?
The same concept as platformSH
The example code has an error, it's missing a space. It should be " redis: 5.3.1"
Login with SymfonyConnect to post a comment