special sponsors

# Installing PHP Extensions on Lando

Written by: Team Lando Team Lando
Guide Tested: Yes

You may wish to add additional PHP extensions to your Lando PHP service. There are a few different ways you can do this:

Note that both of these strategies make use of underlying utilities provided by the Official Docker PHP Image which is the base image used by Lando's PHP service. We recommend you read more about them over on their docs (opens new window).

Also note that you may need to adapt these slightly depending on the PHP version you are using.

# 1. Using build steps

If installing your PHP extension is fairly trivial and not a long-running operation you may wish to simply use Lando build-steps

Here is an example that uses build-steps to install the xsl and stats extensions.

    type: php
      - apt-get update -y
      - apt install libxslt1-dev -y
      - pecl install stats-2.0.3
      - docker-php-ext-install xsl
      - docker-php-ext-enable stats

You can verify the extension was enabled by running:

lando ssh -s myservice -c "php -m"

A downside of this approach is these steps till run EVERY TIME you do a lando rebuild.

# 2. Using Dockerfiles

If you have complex, lengthy or long running build steps you may wish to create a Dockerfile in your repo that directly extends one of Lando's PHP images (opens new window).

This approach is great if you care about rebuild speed. Docker will cache the resultant image and only rebuild if the Dockerfile changes. By extension this means your lando rebuild will be pretty fast as well.

It also ensures your Landofile does not get unruly.

Here is an example that installs the oci8 and pdo_sqlsrv extension.


    type: php:custom
      image: lando/php:7.3-custom
        context: ./
        dockerfile: Dockerfile.custom
        - "80"


FROM devwithlando/php:7.3-apache-2

# Add php extension helper
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

# Install Oracle Instantclient, OCI8 and Microsoft SQL Server extensions
RUN chmod +x /usr/local/bin/install-php-extensions && sync && \
  install-php-extensions oci8-2.2.0 sqlsrv pdo_sqlsrv

You can verify the extension was enabled by running

lando ssh -s myservice -c "php -m"


If you are interested in checking out the fully-armed and operational source code for this guide then check out this repo here.

Have a Lando question you'd like to see as a guide? Suggest one!
Want to write a Lando guide? Learn how!