😎 Adding symlinks in Lando to speed-up development

— 2 minute read

My laptop just broke, but I was lucky enough to be lent another laptop to keep working until I can have mine fixed.

I didn't want to mess up this computer installing all the software I need to run my development web server (MAMP, MySQL, configuring hosts and virtual hosts, configuring php.ini, what PHP version to use, what WordPress, and so on), so this was the perfect chance to start using Lando, the Docker-based tool that simplifies setting-up development projects: just configure the requirements in a .lando.yml file in the root folder of the project, run lando start, and voilà, my WordPress site will be up and running.

I hit a problem though: I want to be able to modify the source files, and visualize the changes on the site immediately, without having to sync files across folders, which takes time and makes the process rather cumbersome. In my previous MAMP-based set-up, I achieved this by creating symlinks to my source code in the site folders inside the webserver. Lando, however, runs inside Docker containers, where symlinks are not allowed, because my local files and your local files will be different and Docker attempts to create always the same output, no matter where it runs.

However, this issue can fortunately be solved: Lando maps a few host locations to container locations, including the home folder, which is mapped to /user inside the container. And the contents are kept in sync! Hence, because my source files are hosted under ~/GitHubRepos/, I can reference them within the container as /user/GitHubRepos/.

The final step is to create the symlink within the webserver inside the container. For this, I configured a Lando service to execute the ln command to create the symlink. Since I'm developing a WordPress plugin called "GraphQL API", instead of uploading a .zip file to install it, I created a symlink graphql-api under folder /app/wordpress/wp-content/plugins pointing to the plugin source files, which exist under /user/GitHubRepos/graphql-api, like this:

name: graphql-api
recipe: wordpress
config:
webroot: wordpress

services:
appserver:
run_as_root:
- ln -snf /user/GitHubRepos/graphql-api /app/wordpress/wp-content/plugins/graphql-api

This works perfectly! Now, when modifying the source code from my repository, I can see the changes take effect immediately on the testing website. 😎