How to setup a WordPress or Drupal site locally with ddev

blue elephant figurine on macbook pro

DDEV is an open source tool that allows setting up local sites using docker, quickly. You don’t need to know complex concepts about docker to be able to have your local WorpPress or Drupal sites working. You can check their official documentation here https://ddev.com/get-started/ and here https://ddev.readthedocs.io/en/stable/

The steps/commands listed below are the ones that I have needed the most, so I am moving this note to the web as a reference for myself, in the future, or to help others who may needed.

How to install DDEV

  1. Install homebrew, following the steps at: https://brew.sh/
  2. Make sure that you have docker installed. You can follow the steps at this link if not sure how.
  3. Install ddev (MAC): brew install drud/ddev/ddev
  4. You need to run ddev config once per project to set it up. Run this from the folder where you plan to have all the files related to the project. It will ask you three questions:
    1. What’s site name?
      • I recommend that you pick one easy-to-remember word. It will be used for the local domain that you will have to use to open the site in the browser. Example: If you pick localsite as the project name, you will access the site from the browser using https://localsite.ddev.site/ 
    2. What’s the location of the docroot?
      1. This is the folder where you cloned or plan to clone the files for the project. I recommend creating a folder called web in the same folder where you run the ddev config command from the step 1. 
    3. What type of project is it? Such as Drupal, PHP, WordPress, etc.
  5. You need to run ddev start to have the project up and running. You can run the command from outside of the folder if you remember the project name.
  6. Want to import a database? You can run ddev import-db –src=dumpfile.sql.gz from the project directory. It will drop the database for you before importing the new database backup.
  7. What about if you need to run composer, drush or wp-cli commands? You should run ddev ssh
  8. Are you having an error and need to see the logs? You should run: ddev logs -f
  9. I have needed to run this command before I was able to run drush on some of my Drupal projects: ddev composer require drush/drush
  10. Need to get the URL of the sites, the port or check if the services are active? ddev describe will give you that info.
  11. If you need to have your local sites using with https, you should run: mkcert -install
  12. Need to debug PHP code with xdebug? You will need to run ddev xdebug to enable it. ddev xdebug off will turn it off again.
  13. You are on mac, and your local sites are super slow, you should run ddev config global –mutagen-enabled and it will enabled mutagen globally. You will notice the difference immediately.
  14. If you followed the step 12, and need to update a lot of files (maybe updating plugins or modules?), mutagen may be slow to pick the updated files, so you may need to run ddev mutagen sync to accelerate the sync process.
  15. Need to test your site with a different PHP version, so you can use ddev config –php-version 8.0 8.0 can be any PHP version that you need.
  16. To install memcached:
    1. In the latest ddev version you will need to run: ddev get drud/ddev-memcached && ddev restart
    2. For WordPress, in the wp-config.php, you will need to add the following lines:
/**
 * Memcache settings.
 */
$memcached_servers = [
    'default' => [
        'ddev-YOUR_PROJECT_NAME-memcached:11211',
    ]
];

# replace the key per project and keep it in git
define( 'WP_CACHE_KEY_SALT', 'random_cache_key_salt' );

Posted

in

, ,

by