Drupal is a free and open source content management framework written in PHP and distributed under the GNU General Public License. Drupal provides a back-end framework for at least 2.3% of all web sites worldwide – ranging from personal blogs to corporate, political, and government sites.
Before you get started with this recipe, we assume that you have:
- Installed Lando and gotten familiar with its basics
- Initialized a Landofile for your codebase for use with this recipe
- Read about the various services, tooling, events, and routing Lando offers.
However, because you are a developer and developers never ever RTFM you can also run the following commands to try out this recipe with a vanilla install of Drupal 7.
# Initialize a drupal7 recipe using the latest drupal 7 version lando init \ --source remote \ --remote-url https://ftp.drupal.org/files/projects/drupal-7.61.tar.gz \ --remote-options="--strip-components 1" \ --recipe drupal7 \ --webroot . \ --name my-first-drupal7-app # Start it up lando start # List information about this app. lando info
Here are the configuration options, set to the default values, for this recipe. If you are unsure about where this goes or what this means, we highly recommend scanning the recipes documentation to get a good handle on how the magicks work.
recipe: drupal7 config: php: '7.2' via: apache:2.4 webroot: . database: mysql:5.7 drush: ^8 xdebug: false config: database: SEE BELOW php: SEE BELOW server: SEE BELOW vhosts: SEE BELOW
Note that if the above config options are not enough all Lando recipes can be further extended and overridden.
Choosing a php version
Here is the recipe config to set the Drupal 7 recipe to use
recipe: drupal7 config: php: '7.0'
Choosing a webserver
By default, this recipe will be served by the default version of our apache service but you can also switch this to use
nginx. We highly recommend you check out both the apache and nginx services before you change the default
With Apache (default)
recipe: drupal7 config: via: apache
recipe: drupal7 config: via: nginx
Choosing a database backend
By default, this recipe will use the default version of our mysql service as the database backend, but you can also switch this to use
mariadb or 'postgres' instead. Note that you can also specify a version as long as it is a version available for use with Lando for either
Also, note that like the configuration of the
php version you should consult the Drupal 7 requirements to make sure the
version you select is supported by Drupal 7 itself.
Using MySQL (default)
recipe: drupal7 config: database: mysql
recipe: drupal7 config: database: mariadb
recipe: drupal7 config: database: postgres
Using a custom version
recipe: drupal7 config: database: postgres:9.6
By default, our Drupal 7 recipe will globally install the latest version of Drush 8 or the latest version of Drush 7 if you are using php 5.3. This means that you should be able to use
lando drush out of the box.
That said you can configure this recipe to use any version of Drush to which there is a resolvable package available via
composer. That means that the following are all valid.
Use the latest version of Drush
recipe: drupal7 config: drush: "*"
Use the latest version of Drush 7
recipe: drupal7 config: drush: ^7
Use a specific version of Drush 8
recipe: drupal7 config: drush: 8.1.15
Using a site-local Drush
While Lando will globally install Drush for you it is increasingly common and in some cases a straight-up best practice to install a site-local Drush by requiring it in your projects
Because of how Lando's php service sets up its
PATH this means that if you have indeed installed Drush on your own via
composer Lando will use yours over its own. Said more explicitly: if you've required
composer in your application then this recipe will use your
drush and not the one you've specified in this recipes config.
If you are using a site-local Drush it is also recommended to configure a build step to automatically install Drush before your app starts up. This can prevent weird version mismatches and other issues if you are using Drush in other Lando automation like events.
Automatically composer install before my app starts
recipe: drupal7 services: appserver: build: - composer install
If you find that Lando is not using your
drush as expected, which can happen if you've modified
composer to install in a different directory than its normal
vendor you can take advantage of Lando's tooling overrides and specify an absolute path to your Drush.
tooling: drush: cmd: /path/to/my/drush
Default URL Setup
You may see
http://default show up in many
drush commands you run.
lando drush uli // http://default/user/reset/1/1548025070/Px6PbLyJ_2laXqoDe6OukHXaX-cXExo4ErfrKbkqsE4/login
This happens because it is actually a difficult problem for Lando to 100% know the canonical URL or service that is serving your application. However, you can set up your environment so that commands like
lando drush uli return the proper URL.
Create or edit the relevant
settings.php file and add these lines. Note that you may need to specify a port depending on your Lando installation. You can run
lando info to see if your URLs use explicit ports or not.
$base_url = "http://mysite.lndo.site:PORT_IF_NEEDED"
You can also use
drush aliases with a command like
lando drush @sitealias cc all by following the instructions below.
Make sure the alias file exists within the drush folder in your app. An example could be the files structure below.
|-- app |-- drush |-- yoursite.aliases.drushrc.php
services: appserver: build: - /bin/sh -c "mkdir -p ~/.drush/site-aliases" - /bin/sh -c "ln -sf /app/drush/yoursite.aliases.drushrc.php ~/.drush/site-aliases/yoursite.drushrc.php"
Configuring your root directory
If you are using a webroot besides
. you will need to remember to
cd into that directory and run
lando drush from there. This is because many site-specific
drush commands will only run correctly if you run
drush from a directory that also contains a Drupal site.
If you are annoyed by having to
cd into that directory every time you run a
drush command you can get around it by overriding the
drush tooling command in your Landofile so that Drush always runs from your
Note that hardcoding the
root like this may have unforeseen and bad consequences for some
drush commands such as
tooling: drush: service: appserver cmd: drush --root=/app/PATH/TO/WEBROOT
recipe: drupal7 config: xdebug: true|false
However, for more information we recommend you consult the php service documentation.
Using custom config files
You may need to override our default Drupal 7 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 below.
Note that the default files may change based on how you set both
via. Also note that the
server config will be either for
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
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
./ |-- config |-- default.conf |-- my-custom.cnf |-- php.ini |-- server.conf |-- index.php |-- .lando.yml
Landofile using custom drupal7 config
recipe: drupal7 config: config: database: config/my-custom.cnf php: config/php.ini server: config/server.conf vhosts: config/default.conf
Connecting to your database
Lando will automatically set up a database with a user and password and also set an environment variable called
LANDO INFO that contains useful information about how your application can access other Lando services.
Here are is the default database connection information for a Drupal 7 site. Note that the
host is not
database: drupal7 username: drupal7 password: drupal7 host: database # for mysql port: 3306 # for postgres # username: postgres # password: '' # port: 5432
You can get also get the above information, and more, by using the
lando info command.
Importing Your Database
Once you've started up your Drupal 7 site you will need to pull in your database and files before you can really start to dev all the dev. Pulling your files is as easy as downloading an archive and extracting it to the correct location. Importing a database can be done using our helpful
lando db-import command.
# Grab your database dump curl -fsSL -o database.sql.gz "https://url.to.my.db/database.sql.gz" # Import the database # NOTE: db-import can handle uncompressed, gzipped or zipped files # Due to restrictions in how Docker handles file sharing your database # dump MUST exist somewhere inside of your app directory. lando db-import database.sql.gz
You can learn more about the
db-import command over here
By default, each Lando Drupal 7 recipe will also ship with helpful dev utilities.
This means you can use things like
php via Lando and avoid mucking up your actual computer trying to manage
php versions and tooling.
lando composer Runs Composer commands lando db-export [file] Exports database from a service into a file lando db-import <file> Imports a dump file into database service lando drush Runs Drush commands lando mysql Drops into a MySQL shell on a database service lando php Runs PHP commands
# Download a dependency with drush lando drush dl views # Run composer tests lando composer test # Drop into a mysql shell lando mysql # Check the app's installed php extensions lando php -m
You can also run
lando from inside your app directory for a complete list of commands which is always advisable as your list of commands may not 100% be the same as the above. For example if you set
database: postgres you will get
lando psql instead of