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

Installed Extensions

  • apc (in php 5.3 and 5.4)
  • bcmath
  • bz2
  • calendar
  • Core
  • ctype
  • curl
  • date
  • dom
  • exif
  • fileinfo
  • filter
  • ftp
  • gd
  • hash
  • iconv
  • imagick
  • imap
  • 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

You can install your own extensions using the extras 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:
    extras:
      - "apt-get update"
      - "apt-get install libmemcached-dev -y"
      - "pecl install memcached"
      - "docker-php-ext-enable memcached"

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"

    # Optionally run the following build steps
    # build:
    #  - "cd $$LANDO_MOUNT && composer install"

    # Optionally install additional server software
    # extras:
    #  - "apt-get update -y"
    #  - "apt-get install netcat -y"

  # 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

# LAMP 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: '*'

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

  # 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 .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
    # build:
    #  - "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 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 ""