Install DDEV on a Mac
Here is a small guide on how to install DDEV, which is based on Docker, where each site gets its own container for web and database.
Install via Homebrew
Install Docker Desktop (if you don't already have it):
brew install docker --cask
Start the Docker Desktop application in Applications.
Install DDEV:
brew install drud/ddev/ddev
Install local certificates (once):
mkcert -install
To upgrade ddev, run:
brew upgrade ddev
Add a site that is already configured (a) or add a new one (b).
1a.) Add an already configured site
If someone else has already created a .ddev directory in the project, it's enough to go to the directory with the repo (e.g., cd ~/Sites/rclient-site) and run:
ddev start
1b.) Add a new site in DDEV
If it's the first time adding a project to DDEV, you need to run ddev config. Go to the directory in the terminal (e.g., cd ~/Sites/client-site) and run:
ddev config
Answer the questions and let DDEV do its thing.
2.) Import a database
Once the server is up and all containers are created, you can import a database with:
ddev import-db
3.) New settings
Finally, make sure to change .env and scripts/.env.sh with the new settings. Information about DDEV can be obtained with:
ddev describe
Edit settings (e.g., PHP version, subdomains, etc.)
Edit the file ~/Sites/client-site/.ddev/config.yaml and save.
Apply the new configuration with:
ddev stop
ddev start
or
ddev restart
SSH
You can SSH into the local environment with the following command:
ddev ssh
To share local SSH keys with DDEV:
ddev auth ssh
Composer auth
To share your auth.json from .composer on your local computer with all DDEV containers, you can run the following command:
mkdir -p ~/.ddev/homeadditions/.composer && ln -s ~/.composer/auth.json ~/.ddev/homeadditions/.composer/auth.json
Database
To access the database in TablePlus, you need to connect to 127.0.0.1 and the port that the container has. Each site has its own container with its database manager.
In Craft’s .env, use Docker's domain, for example ddev-client-site-db, and not localhost.
To import a database, run ddev import-db and follow the steps there to choose which file (.sql/.gz) you want to import to your database. The database is named db by default (but you can also create other databases in each database container).
If you want to import data into a database other than the db database, you can run the following command: ddev import-db --target-db <some_database>.
.env
DB_DRIVER="mysql"
DB_SERVER="ddev-republic-db"
DB_USER="db"
DB_PASSWORD="db"
DB_DATABASE="db"
DB_SCHEMA="public"
DB_TABLE_PREFIX=""
DB_PORT="3306"
scripts/.env.sh
# Local database constants;
LOCAL_DB_NAME="db"
LOCAL_DB_USER="db"
LOCAL_DB_PASSWORD="db"
LOCAL_DB_HOST="ddev-republic-db"
LOCAL_DB_PORT="3306"
LOCAL_DB_SCHEMA="public"
Open the database in TablePlus from the terminal
DDEV has built-in support for opening TablePlus directly from the terminal via ddev tableplus. Since we run TablePlus via Setapp, we need to create a symlink from /Applications.
cd /Applications
ln -s /Applications/Setapp/TablePlus.app TablePlus.app
Then you can open the database in TablePlus via:
cd ~/Sites/maurten
ddev tableplus
Craft
You can access the Craft command via ddev craft.
Shut down DDEV
Generally, ddev restart, ddev stop, and ddev start are sufficient to manage DDEV.
To shut down all containers at once, you can run ddev poweroff. If you run that command, you will need to share your SSH keys with DDEV the next time you start a container.