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 easily add it to your Lando app by adding an entry to the services top-level config in your Landofile.
Supported versions
Legacy versions
Using Unsupported PHP Versions!
While you can currently use some EOL php version 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".
You can still run these versions with Lando but for all intents and purposes they should be considered deprecated eg YMMV and do not expect a ton of support if you have an issue.
Patch versions
Because we use our own custom images for php
specifying a patch version is not currently supported.
If you really need to lock down to a patch vesrion you could consider using either a custom compose service or a service overrides.
Configuration
Here are the configuration options, set to the default values, for this service. If you are unsure about where this goes or what this means we highly recommend scanning the services documentation to get a good handle on how the magicks work.
Also note that the below options are in addition to the build steps and overrides that are available to every service.
services:
my-service:
type: php:7.3
via: apache:2.4
ssl: false
webroot: .
xdebug: false
composer: []
config:
php: SEE BELOW
server: SEE BELOW
vhosts: SEE BELOW
Choosing a server, or no server
By default php
services will be served by the default version of our apache service but you can switch this to either nginx
or cli
.
Like with apache
, nginx
will use the the default version of our nginx service while cli
will just spin up a php
container without a webserver. The latter is useful if you just want to work on a CLI utility or lock down what version composer
runs with.
With Apache (default)
services:
my-service:
type: php
via: apache
With nginx
services:
my-service:
type: php
via: nginx
** As CLI **
services:
my-service:
type: php
via: cli
Toggling xdebug
You can enable the xdebug
extension by setting xdebug: true
. Lando will also automatically configure xdebug.remote_enable
and xdebug.remote_host
for you. This means that xdebug
should be ready to receive connections out of the box.
Note that unlike in previous versions of Lando xdebug: false
will now disable the xdebug
extension instead of just disabling xdebug.remote_enable
Setting up your IDE for XDEBUG
While Lando will handle the server side configuration for you, there is often a considerable amount of pain lurking in the client side configuration. To that end here is some helpful info about a few popular clients.
ATOM
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
.
VSCODE
Setup XDebug in Visual Studio Code Guide
Troubleshooting Xdebug
Problems starting XDEBUG
If you are visiting 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.
If you have set xdebug: true
in your recipe or service config and run lando rebuild
but are still having issues getting xdebug
to work correctly we recommend that you remove xdebug: true
, run lando rebuild
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.
Installing global dependencies
You can also use the composer
key if you need to require any global composer dependenices. This follows the same syntax as your normal composer.json
except written as YAML instead of JSON.
Use composer.json if you can
While there are some legitimate use cases to globally install a composer dependency it is almost always preferred to install using your applications normal composer.json
and then running either lando composer install
or alternatively setting up a build step that will automatically run before your app starts up.
Note that both lando composer
is not provided out of the box by the php
service and need to be manually added by configuring your app's tooling.
Here is an example of globally installing phpunit/phpunit
^6.5
services:
my-service:
type: php
composer:
phpunit/phpunit: ^6.5
Here is an example of using a build step to automatically composer install
your dependencies before your app starts.
services:
my-service:
type: php
build:
- composer install
Using custom config files
You may need to override our default php config with your own.
If you do this you must use files that exists inside your applicaton and express them relative to your project root as below.
Note that the default files may change based on how you set both ssl
and via
. Also note that the vhosts
and server
config will be either for apache
or nginx
depending on how you set via
. We highly recommend you check out both the apache and nginx if you plan to use a custom vhosts
or server
config.
If you set via: cli
then, as you might suspect, vhosts
and/or server
is not going to do anything.
A hypothetical project
Note that you can put your configuration files anywhere inside your application directory. We use a config
directory in the below example but you can call it whatever you want such as .lando
.
./
|-- config
|-- default.conf
|-- nginx.conf
|-- php.ini
|-- index.php
|-- .lando.yml
Landofile using custom php config
services:
my-service:
type: php
config:
php: config/php.ini
server: config/nginx.conf
vhosts: config/default.conf
Path Considerations
Lando will set the following PATH
hierarchy for this service.
[
# The line below should be where your app's composer.json binaries live
'/app/vendor/bin',
'/usr/local/sbin',
'/usr/local/bin',
'/usr/sbin',
'/usr/bin',
'/sbin',
'/bin',
# The line below should be where global composer binaries live
'/var/www/.composer/vendor/bin',
]
This is useful to note if you are not using absolute paths in any tooling routes and are getting the unexpected version of a particular utility.
Installed Extensions
5.3 | 5.4 | 5.5 | 5.6 | 7.0 | 7.1 | 7.2 | 7.3 | |
---|---|---|---|---|---|---|---|---|
apc | X | X | ||||||
apcu | X | X | X | X | X | X | ||
bcmath | X | X | X | X | X | X | X | X |
bz2 | X | X | X | X | X | X | X | X |
calendar | X | X | X | X | X | X | X | X |
Core | X | X | X | X | X | X | X | X |
ctype | X | X | X | X | X | X | X | X |
curl | X | X | X | X | X | X | X | X |
date | X | X | X | X | X | X | X | X |
dom | X | X | X | X | X | X | X | X |
exif | X | X | X | X | X | X | X | X |
fileinfo | X | X | X | X | X | X | X | X |
filter | X | X | X | X | X | X | X | X |
ftp | X | X | X | X | X | X | X | X |
gd | X | X | X | X | X | X | X | X |
gettext | X | X | X | X | X | X | X | X |
hash | X | X | X | X | X | X | X | X |
iconv | X | X | X | X | X | X | X | X |
imagick | X | X | X | X | X | X | X | X |
imap | X | X | X | X | X | X | X | X |
intl | X | X | X | X | X | X | X | X |
json | X | X | X | X | X | X | X | X |
ldap | X | X | X | X | X | X | X | X |
libxml | X | X | X | X | X | X | X | X |
mbstring | X | X | X | X | X | X | X | X |
mcrypt | X | X | X | X | X | X | X | X |
memcached | X | X | X | X | X | X | X | X |
mysqli | X | X | X | X | X | X | X | X |
mysqlnd | X | X | X | X | X | X | X | X |
OAuth | X | X | X | X | X | X | X | X |
OPcache | X | X | X | X | X | X | ||
openssl | X | X | X | X | X | X | X | X |
pcntl | X | X | X | X | X | X | X | X |
pcre | X | X | X | X | X | X | X | X |
PDO | X | X | X | X | X | X | X | X |
pdo_mysql | X | X | X | X | X | X | X | X |
pdo_pgsql | X | X | X | X | X | X | X | X |
pdo_sqlite | X | X | X | X | X | X | X | X |
Phar | X | X | X | X | X | X | X | X |
posix | X | X | X | X | X | X | X | X |
readline | X | X | X | X | X | X | X | X |
redis | X | X | X | X | X | X | X | X |
readline | X | X | X | X | X | X | X | X |
Reflection | X | X | X | X | X | X | X | X |
session | X | X | X | X | X | X | X | X |
SimpleXML | X | X | X | X | X | X | X | X |
soap | X | X | X | X | X | X | X | X |
SPL | X | X | X | X | X | X | X | X |
sqlite3 | X | X | X | X | X | X | X | X |
standard | X | X | X | X | X | X | X | X |
tokenizer | X | X | X | X | X | X | X | X |
xdebug | ||||||||
xml | X | X | X | X | X | X | X | X |
xmlreader | X | X | X | X | X | X | X | X |
xmlwriter | X | X | X | X | X | X | X | X |
zip | X | X | X | X | X | X | X | X |
zlib | X | X | X | X | X | X | X | X |
Note that xdebug
is off by default but you can enable it on by setting your php
services config to xdebug: true
. Read more about this in "Configuration" above.
Adding or removing extensions
There are a few ways you can extend or modify our php images:
- Using build steps
- Using your own image with service overrides
- Building from your own local Dockerfile service overrides
Consider the following example that uses build steps to install the memcached
php extension.
services:
my-service:
type: php
build_as_root:
- apt-get update -y
- apt-get install libmemcached-dev -y
- pecl install memcached
- docker-php-ext-enable memcached
Note the usage of docker-php-ext-enable
. Our images extend the official Docker php images which ship with a bunch of helpful utility scripts to manage php extensions.
← Node PhpMyAdmin →