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
.htaccessrules apply just as they will on most hosts:
ddev config --project-type=php --docroot=. --php-version=8.3 --webserver-type=apache-fpm
- Run
ddev startfrom 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 startprints (for examplehttps://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
.ddevfolder adddocker-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 servicesddev ssh- Connects a shell to the webserver at the docroot.ddev exec 'params'- Executes params at the docroot (e.g.ddev exec bin/grav clearto clear the cache, orddev exec bin/gpm install admin2to 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.