Symfony News

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 https://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!


Sponsor the Symfony project.


About us

What a Symfony developer should know about the framework: News, Jobs, Tweets, Events, Videos,...

Find us on Twitter

Find us on Facebook

ADS