PHP is a popular scripting language that is especially suited for web development. It is often served by either apache, nginx, or caddy.
You can easily add it to your Lando app by adding an entry to the services top-level config in your Landofile.
services:
myservice:
type: adeliom-php:8.0
via: nginx
webroot: www
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 options, in addition to the build steps and overrides that are available to every service, are shown below:
services:
myservice:
type: adeliom-php:7.4
via: apache
webroot: .
xdebug: false
composer: []
# Below only valid for via: cli
command: tail -f /dev/null
config:
php: SEE BELOW
By default, php
services will be served by default with [apache] service but you can switch this to either nginx
, caddy
, or cli
.
Unlike with apache
, nginx
or caddy
the cli
will just spin up a php
container without a web server. The latter is useful if you just want to work on a CLI utility or lock down what version composer
runs with.
services:
myservice:
type: adeliom-php
via: apache
services:
myservice:
type: adeliom-php
via: nginx
services:
myservice:
type: adeliom-php
via: caddy
services:
myservice:
type: adeliom-php
via: cli
In CLI mode you can optionally tell the php cli service to boot up with an arbitrary command, this is good for php worker services like queues.
services:
myservice:
type: adeliom-php
via: cli
command: php /app/src/artisan horizon
By default Lando will serve the app from the root of your repo. If you'd like to serve your application from a different directory then use webroot
.
services:
myservice:
type: adeliom-php
via: nginx
webroot: docroot
You can enable the node
by setting the version and doing a lando rebuild
.
services:
myservice:
type: adeliom-php:7.4
node: "18"
You can enable wkhtmltopdf
and wkhtmltoimage
by setting wkhtmltopdf: true
and doing a lando rebuild
.
In xdebug
version you can optionally specify the mode.
services:
myservice:
type: adeliom-php:7.4
wkhtmltopdf: true
You can enable the xdebug
extension by setting xdebug: true
and doing a lando rebuild
. When the extension is enabled Lando will automatically set the needed configuration for remote debugging. This means that xdebug
should be ready to receive connections out of the box.
In xdebug
version you can optionally specify the mode.
services:
myservice:
type: adeliom-php:7.4
xdebug: "debug,develop"
For this version of xdebug
setting xdebug: true
will set xdebug.mode=debug
. You can read more about xdebug.mode
here.
If you'd like to override Lando's out of the box xdebug
config the easiest way to do that is by setting the XDEBUG_CONFIG
environment variable as a service level override.
services:
myservice:
type: adeliom-php:7.4
xdebug: "debug,develop"
overrides:
environment:
XDEBUG_CONFIG: "discover_client_host=0 client_host=localhost"
Note that you cannot set every xdebug
configuration option via XDEBUG_CONFIG
, see this. If you need to configure something outside of the scope of XDEBUG_CONFIG
we recommend you use a custom php.ini
.
You can also modify or unset XDEBUG_MODE
in a similar way. For example if you wanted to manage xdebug.mode
in your own php.ini
you could so something like
services:
myservice:
type: adeliom-php:7.4
xdebug: true
overrides:
environment:
XDEBUG_MODE:
config:
php: config/php.ini
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, some helpful info about a few popular clients is shown below:
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
::: tip Problems starting XDEBUG
If you are visiting your site and xdebug is not triggering, it might be worth appending ?XDEBUG_SESSION_START=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 as shown 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.
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.
::: tip 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 lando composer
is not provided out of the box by the php
service and needs to be manually added by configuring your app's tooling.
:::
An example of globally installing phpunit/phpunit
^6.5
is shown below:
services:
myservice:
type: adeliom-php
composer:
phpunit/phpunit: ^6.5
An example of using a build step to automatically composer install
your dependencies before your app starts is shown below:
services:
myservice:
type: adeliom-php
build:
- composer install
You may need to override our default php.ini config with your own.
If you do this, you must use files that exist inside your application and express them relative to your project root as shown below:
A hypothetical project
Note that you can put your configuration files anywhere inside your application directory. We use a config
directory but you can call it whatever you want such as .lando
in the example below:
./
|-- config
|-- php.ini
|-- index.php
|-- .lando.yml
Landofile using custom php config
services:
myservice:
type: adeliom-php
config:
php: config/php.ini
By default a service will not do any tooling routing for you but you can add helpful lando
commands.
tooling:
php:
service: myservice
composer:
service: myservice
You can then invoke them on the command line.
lando php
lando composer
Lando tooling is actually pretty powerful so definitely check out the rest of its cool features.
By default a service will not do any proxy routing for you but you can add your own.
proxy:
myservice:
- myapp.lndo.site
- something.else.local
Lando proxying is actually pretty powerful so definitely check out the rest of its cool features.