Developing a Drupal 8 site or blog with a hosting plan that supports Drupal 8 installation is relatively easy to do than doing it locally. This adds to the upfront cost, even though you just wanted to see how Drupal 8 works.
If you wish to develop a Drupal 8 blog or site locally, there are few solutions that can help you to do so.
‘Acquia Dev Desktop’ is one of them, it helps in creating a local development environment for Drupal 8. But, it only have installer for Mac and Windows.
Installing ‘Ampps’, ‘WampServer’, or a ‘LAMP’/’LEMP’ stack could be one of the option as well.
But, I have found Lando makes it easier to do so. Irrespective of the operating system or distro you are working on. Moreover, it runs as an ‘abstraction layer’ to spin up docker containers with sane defaults.
Let us look at the steps on how to install and use Lando for creating a local development environment for Drupal 8.
1. Prerequisites for creating a development environment for Drupal 8 with Lando:
1. Install Docker
For Lando to work, we need to install Docker for Mac/Docker for Windows/Docker CE (if it’s not already installed).
2. Install Lando
Download the latest
.rpmpackage from Lando’s GitHub repository (Download the correct package depending on your OS or distro).
Install the package.
If your distro uses a docker group, make sure your user is a member of it.
Commands for doing so will be something like:
$ sudo groupadd docker
$ sudo usermod -aG docker $USER
Note: Visit here for more details on this: https://docs.docker.com/install/linux/linux-postinstall/
Verify that you can run docker commands without sudo.
$ docker run hello-world
To see complete documentation on Installing Lando for your OS, visit appropriate links:
3. Install Composer
Composer needs to be installed globally. This will ensure to pull Drupal 8 codebase using composer.
4. Install NodeJS and NPM
‘nodejs’ and ‘npm’ should be installed to install npm packages. Themes or some modules for Drupal 8 might need these packages.
2. Creating the Local development environment for Drupal 8 with Lando.
Open the terminal from home directory. This can be from anywhere as well. Note: You may use Git Bash if you are using windows.
Use the following command to create a folder named ‘my_site_name_dir’ and pull the Drupal 8 code inside it.
$ composer create-project drupal-composer/drupal-project:8.x-dev my_site_name_dir --stability dev --no-interaction
Note: Change ‘my_site_name_dir’ to ‘drupaldev’ for this example.
Go inside the created directory.
.lando.ymlfile (inside the directory ‘drupaldev’) with Drupal 8 recipe mentioned here: https://docs.devwithlando.io/tutorials/drupal8.html
Open the terminal from this directory. (Be sure about your path when in terminal. You should be inside the ‘drupaldev’ directory.) Enter the following command:
$ lando start
The above command will create services like
mysqlnecessary for Drupal 8 development environment. Note the details shown in the output, we will need this to access the Drupal site later.
We can also use
$ lando infoto get this information.
Use this command to install drush 8.x or downgrade the previous version installed.
lando composer require drush/drush 8.x
A development environment for Drupal 8 has been created.
Now we are ready to experiment and start developing with Drupal 8.
Note: Use the command
$ lando stopto kill the app (environment) created. To completely erase the database and server environment use:
$ lando destroy [app name]
- Official page for ‘drupal-composer/drupal-project’: https://github.com/drupal-composer/drupal-project
- Lando documention for Drupal 8: https://docs.devwithlando.io/tutorials/drupal8.html
- Drupal documentation for using Composer to manage Drupal site dependencies: https://www.drupal.org/docs/develop/using-composer/using-composer-to-manage-drupal-site-dependencies
- Drupal Composer installation guide: https://www.drupal.org/docs/user_guide/en/install-composer.html
- This blog by Jeff Geerling is helpful: https://www.jeffgeerling.com/blog/2018/getting-started-lando-testing-fresh-drupal-8-umami-site
You may add your impressions regarding the blog post here: