Skip to content

Powered by Grav + Helios

Local Development with ddev

Local Development with ddev

ddev is an open-source, PHP development tool, built upon Docker. It can easily create local hosting environments, and its server configurations can be version controlled. It can host almost any PHP project, Grav included. Since it is based on Docker, ddev is compatible with Windows, Mac, and Linux.

Installing ddev

Please see the official ddev documentation for the most up to date instructions for installing ddev.

Configuration

  • Place the Grav files in a folder on the host machine (/home/USER/projects/grav).
  • In your terminal, cd to that folder cd /home/USER/projects/grav
  • Configure the project. Grav 2 needs PHP 8.3 or newer, and running DDEV's Apache web server lets Grav's bundled .htaccess rules apply just as they will on most hosts:
BASH
ddev config --project-type=php --docroot=. --php-version=8.3 --webserver-type=apache-fpm
  • Run ddev start from the [GRAV_ROOT] folder.
  • Let ddev build out the containers it requires. Root/ Sudo credentials may be required in order to make local hosts changes.
  • Open the URL ddev start prints (for example https://grav.ddev.site). With the Grav + Admin package, the first visit takes you to the admin's setup page to create your administrator account.

Note

DDEV's default web server is Nginx, which does not read .htaccess. Its generated config routes requests to index.php but does not include Grav's security rules, so files such as user/config/system.yaml can be fetched directly. That is usually fine on your own machine, but if you prefer Nginx, copy the Index, Security and Static asset caching sections of Grav's webserver-configs/nginx.conf into .ddev/nginx_full/nginx-site.conf and remove the #ddev-generated line so DDEV keeps your changes.

Symlinking

With Grav it is handy to symlink configs, or folders like themes or plugins. Symlinks that point outside the project folder are not resolved in the containers created by DDEV, so add a mount for them instead:

  • in the .ddev folder add docker-compose.mounts.yaml
  • add a mount (expl for themes):
    YAML
        services:
          web:
            volumes:
              - /absolute/path/to/my/themes_repo:/var/www/html/user/themes
    
  • then ddev restart

Using ddev

Run these commands from the [GRAV_ROOT] on the host machine:

  • ddev describe - Views all available services
  • ddev ssh - Connects a shell to the webserver at the docroot.
  • ddev exec 'params' - Executes params at the docroot (e.g. ddev exec bin/grav clear to clear the cache, or ddev exec bin/gpm install admin2 to add the admin)

I need to install [insert plugin/ theme here]. How do I access bin/gpm?

From the [GRAV_ROOT], type ddev ssh and you'll be connected to the web server at the docroot. From here, you can run any php command (composer, bin/gpm, bin/grav, etc).

Where do I edit my files?

An editor on the host machine can edit the files at [GRAV_ROOT]. Changes will reflect into the ddev container automatically. Changes performed in the container (i.e. bin/gpm install admin2) will reflect to the host machine.