php

PHP is a popular scripting language that is especially suited for web development. It is often served by either apache or nginx

You can also use the Hip Hop Virtual Machine by specifying hhvm as the version. This will currently run hvvm:3.20. In the future we will support more version of hhvm. Note that if you specify hhvm it will force usage of nginx.

You can easily add php or hhvm to your Lando app by adding an entry to the services key in your app's .lando.yml.

Supported Versions

Using Unsupported PHP Versions

While you can use currently EOL php versions with Lando it's worth noting that we also do not support such versions so your mileage may vary. If you are having issues with unsupported versions and open a ticket about it, the most likely response you will get is "upgrade to a supported version".

Using patch versions

Because we use our own custom image for php specifying a patch version is not currently supported. If you need to use a patch version you might be able to use our advanced service config.

Installed Extensions

  • apc (in php 5.3 and 5.4)
  • apcu (in php 5.5+)
  • bcmath
  • bz2
  • calendar
  • Core
  • ctype
  • curl
  • date
  • dom
  • exif
  • fileinfo
  • filter
  • ftp
  • gd
  • gettext
  • hash
  • iconv
  • imagick
  • imap
  • intl
  • json
  • ldap
  • libxml
  • mbstring
  • mcrypt
  • memcached
  • mysqli
  • mysqlnd
  • OAuth
  • openssl
  • pcre
  • PDO
  • pdo_mysql
  • pdo_pgsql
  • pdo_sqlite
  • Phar
  • posix
  • readline
  • redis
  • Reflection
  • session
  • SimpleXML
  • soap
  • SPL
  • sqlite3
  • standard
  • tokenizer
  • xdebug
  • xml
  • xmlreader
  • xmlwriter
  • Zend OPcache (in php 5.5+)
  • zip
  • zlib

Installing Your Own Extensions

Using Build Steps

You can install your own extensions using the run_as_root build step. Here is an example that installs the memcached extensions. Note that you will likely need to restart your app after this step for the extension to load correctly!

services:
  appserver:
    run_as_root:
      - "apt-get update"
      - "apt-get install libmemcached-dev -y"
      - "pecl install memcached"
      - "docker-php-ext-enable memcached"

Using a Dockerfile

Alternatively you can extend our base php image by overriding your service to build from a Dockerfile that lives somewhere inside your app.

Landofile

# Dockerfile example
name: dockerfile

# Start with the default LEMP recipe
recipe: lemp

# Override the recipe image with a build location
services:
  appserver:

    # You probably want to set this to custom
    type: php:custom
    overrides:
      services:

        # This should relative to your app root
        build: ./php

        # Optionally specify a name and tag for the built image so you can
        # user it elsewhere later
        #
        # NOTE: Docker may throw a warning like:
        #   WARNING: Image for service appserver was built because it did not already exist.
        # This is safe to ignore
        image: pirog/php:7.1-fpm-custom

        # This is not needed it only serves to illustrate how you can map internal container things
        # to your app directory for easy editability
        volumes:
          - ./config/custom.ini:/usr/local/etc/php/conf.d/zzzz-custom.ini
          - ./logs:/var/logs

Dockerfile

FROM devwithlando/php:7.1-fpm

RUN apt-get update -y \
  && docker-php-ext-install pcntl

You can check out the full code for this example over here.

LAMP Example

# LAMP stack example
name: lamp

# Give me http://lamp.lndo.site and https://lamp.lndo.site
proxy:
  appserver:
    - lamp.lndo.site

# Spin up services to run a basic LAMP stack
services:

  # Create a php 5.3 instance served by the latest apache with https turned on
  appserver:

    # PHP version 5.3
    type: php:5.3

    # Serve php by either apache or nginx. You can put in any `service:version`
    # string that is supported by Lando's nginx and apache services.
    via: apache

    # Optionally serve php over https
    ssl: true

    # Optionally specify a webroot if it is a subdirectory of the appRoot
    webroot: www

    # Optionally customize the configuration for php and its underlying webserver
    # These paths are both relative to (and must reside within) the app root directory
    #
    # For some examples that use this fairly well please check out
    # https://github.com/lando/lando/tree/master/examples
    # config:
      # Use a custom apache config file
      # server: config/apache/lamp.conf

      # Use a custom php.ini
      # This **should** load last which means you should be able to override
      # any previously set php settings.
      # conf: config/php/php.ini

    # Optionally activate xdebug
    #
    # If you are having trouble getting xdebug to work please see:
    # https://docs.devwithlando.io/services/php.html#using-xdebug
    xdebug: true

    # Optionally install the following composer dependencies globally
    # These follow the normal composer.json form
    # Note that many composer dependencies should not be installed globally but
    # on a per-project basis
    # composer:
    #   drush/drush: "~8"

  # My database service
  database:
    type: mysql
    portforward: 3308
    creds:
      user: lamp
      password: lamp
      database: lamp

# Add some nice command routing
tooling:
  composer:
    service: appserver
    description: Run composer commands
    cmd: composer --ansi
  php:
    service: appserver
  mysql:
    user: root
    service: database
    description: Drop into a MySQL shell

You will need to rebuild your app with lando rebuild to apply the changes to this file. You can check out the full code for this example over here.

LEMP Example

# LEMP stack example
name: lemp

# Give me http://lemp.lndo.site and https://lemp.lndo.site
proxy:
  nginx:
    - lemp.lndo.site

# Spin up services to run a basic LEMP stack
services:

  # Create a php 7.1 instance served by the latest nginx with https turned on and
  # served from the www subdirectory
  appserver:

    # PHP version .1
    type: php:7.1

    # Served by the latest nginx
    via: nginx

    # Optionally serve php over https
    ssl: true

    # Optionally specify a webroot if it is a subdirectory of the appRoot
    webroot: www

    # Optionally activate xdebug
    #
    # If you are having trouble getting xdebug to work please see:
    # https://docs.devwithlando.io/services/php.html#using-xdebug
    xdebug: true

    # Optionally customize the configuration for php and its underlying webserver
    # These paths are both relative to (and must reside within) the app root directory
    #
    # For some examples that use this fairly well please check out
    # https://github.com/lando/lando/tree/master/examples
    config:

      # Use a custom nginx config file
      server: config/nginx/default.conf

      # Use a custom php.ini
      # This **should** load last which means you should be able to override
      # any previously set php settings.
      conf: config/php/php.ini

    # Optionally install the following composer dependencies globally
    # These follow the normal composer.json form
    # Note that many composer dependencies should not be installed globally but
    # on a per-project basis
    composer:
      overtrue/phplint: '*'

  # Add in the latest mariadb
  database:
    type: mariadb
    portforward: 3332
    config:
      confd: config/mysql

  # Add latest node for cli tools
  node:
    type: node:6.10

# Add some nice command routing
tooling:
  phplint:
    service: appserver
  composer:
    service: appserver
    description: Run composer commands
    cmd: composer --ansi
  php:
    service: appserver
  mysql:
    user: root
    service: database
    description: Drop into a MySQL shell
  npm:
    service: node
  node:
    service: node

You will need to rebuild your app with lando rebuild to apply the changes to this file. You can check out the full code for this example over here.

CLI Example

# phpcli example
name: phpcli

# Spin up a php cli
services:

  # Create a php 7.1 cli
  phpcli:

    # PHP version 7.1
    type: php:7.1

    # Set to run in CLI mode
    via: cli

    # Optionally install the following composer dependencies globally
    # These follow the normal composer.json form
    # Note that many composer dependencies should not be installed globally but
    # on a per-project basis
    # composer:
    #  overtrue/phplint: '*'

    # Optionally run the following commands after the service is started
    # Runs composer install but dont fail on an error
    # run:
    #  - "cd $LANDO_MOUNT && composer install || true"

    # Optionally activate xdebug
    #
    # If you are having trouble getting xdebug to work please see:
    # https://docs.devwithlando.io/services/php.html#using-xdebug
    xdebug: true

    # Optionally mix in your own config files
    #
    # If ommitted this will use "sane defaults" for your recipe type
    # conf:

      # For more information on setting these files check out the documentation
      # and examples
      #
      # Docs: https://docs.devwithlando.io/services/php.html
      # Examples: https://github.com/lando/lando/tree/master/examples
      #
      # php: config/php.ini

# Add some nice command routing
tooling:
  composer:
    service: phpcli
    description: Run composer commands
    cmd:
      - composer
      - --ansi
  php:
    service: phpcli

You will need to rebuild your app with lando rebuild to apply the changes to this file. You can check out the full code for this example over here.

Using Xdebug

You can activate xdebug for remote debugging by setting xdebug: true in the config for your php service. This will enable xdebug and configure it so you can connect from your host machine. You will need to configure your IDE so that it can connect.

Here are the instructions to setup XDebug in Visual Studio Code.

Here is some example config for ATOM's php-debug plugin:

"php-debug":
  {
    ServerPort: 9000
    PathMaps: [
      "/app/www;/Users/pirog/Desktop/work/lando/examples/lando/www"
    ]
  }

The first part of a pathmap will be the location of your code in the container. Generally, this should be /app. Also note that if your app is in a nested docroot, you will need to append that to the paths. The example above uses an app with a nested webroot called www.

Problems starting XDEBUG

If you are visting your site and xdebug is not triggering, it might be worth appending ?XDEBUG_START_SESSION=LANDO to your request and seeing if that does the trick.

Troubleshooting

If you have set xdebug: true in your recipe or service config and run lando restart but are still having issues getting xdebug to work correctly we recommend that you remove xdebug: true, run lando restart and then set the relevant xdebug config directly using a custom a php.ini (see examples above on how to set a custom config file). Your config file should minimally include something like below.

xdebug.max_nesting_level = 256
xdebug.show_exception_trace = 0
xdebug.collect_params = 0
xdebug.remote_enable = 1
xdebug.remote_host = YOUR HOST IP ADDRESS

You can use lando info --deep | grep IPAddress to help discover the correct host ip address but please note that this can change and will likely differ from dev to dev.

results matching ""

    No results matching ""