DDEV (DDEV documentation) is a popular tool for local development of Drupal and WordPress projects. By default, DDEV mounts the project code into the container at /var/www/html within the container. However, there might be situations where you want to mount the code at a different location, such as /srv.
Why use /srv instead of /var/www/html?
The /srv directory is a common location for site-specific data in Unix-like operating systems. Some users might prefer to follow this convention for their projects even in a containerized environment.
Error while trying to mount the /srv directory
When attempting to mount the /srv directory, you might encounter issues caused by Mutagen or Docker configuration. This article covers the key concepts and steps required to resolve these issues.
Understanding Mutagen and DDEV configuration
DDEV uses Mutagen (Mutagen website) for faster file syncing between your local machine and the Docker containers. Mutagen utilizes an optimized daemon process for bi-directional file synchronization. With Mutagen, changes in files on either your local machine or the container are reflected instantaneously.
However, there can be issues when mounting a custom directory using DDEV due to incorrect Mutagen configuration. Let's dive deeper into solving these issues, specifically with the /srv directory.
Solving the Mutagen/Docker configuration issues
To mount the /srv directory correctly, update the DDEV configuration and reconfigure the Mutagen bind mount in two steps:
-
Update the DDEV project configuration file,
.ddev/config.yaml.# .ddev/config.yaml name: my_project type: drupal9 web_environment: type: apache document_root: /srv/www/html extra_hosts: [] routes: my_project.test: url: 'http://my_project.test' tls_sni: 'my_project.test' mounts: # Mutagen-managed mount - name: my_project-docroot path: /srv/www/html mount_point: /srv -
Update and reconfigure the Mutagen bind mount.
$ mutagen drive rm my_project-docroot $ mutagen drive add my_project-docroot /path/to/my_project /srv
Testing the configuration
After updating the DDEV configuration and reconfiguring the Mutagen bind mount, start your DDEV project and ensure there are no issues:
$ ddev start
Check the logs to validate the mount and absence of errors:
$ ddev logs
By understanding the configuration of DDEV, Mutagen, and the required modifications to your project setup, you can use the /srv directory for your projects without the need for workarounds.