To follow along with the examples in this guide you'll need to have a copy of the Anytown Farmer's Market site that resembles what you would have if you went through all the chapters in the Drupal User Guide. If you did not follow along with the Drupal User Guide example, or if you need a fresh start, this tutorial will walk you through setting up a copy of the site based on a backup. This guide follows a project-based learning approach, and this setup is essential for ensuring that you can effectively follow along with the subsequent tutorials.
In this tutorial, we'll:
- Locate the codebase, backup database, and backup public files directory, required to restore a copy of the Anytown Farmer's Market site.
- Walk through setting up the site in DDEV using the provided backup.
By the end of this tutorial, you should have a working copy of the Anytown Farmer's Market site on your local development environment.
Goal
Set up your local development environment with a copy of the Anytown Farmer's Market site in order to follow along with the examples in the rest of this guide.
Prerequisites
The files provided here can be used with any Drupal-compatible development environment. We'll provide instructions for using DDEV. If you're not using DDEV, modify the instructions by replacing or removing ddev
commands with ones appropriate for your local environment.
Video tutorial
Anytown Farmer's Market site backup files
The files for the Anytown Farmer's Market site can be found on GitHub at DrupalizeMe/module-developer-guide-demo-site.
The Git repository contains everything needed to create a copy of the site:
- A Composer-based Drupal project based on the standard
drupal/core-recommended
install. Must be initialized withcomposer install
. - backups/d10.start-here.sql.gz: An SQL dump of the Anytown Farmer's Market site that corresponds to the state of the site if you had completed all chapters of the Drupal User Guide.
- backups/public_files.tar.gz: The content of the sites/default/files directory for the Anytown Farmer's market site if you had completed all chapters of the Drupal User Guide.
Try GitPod.io + DDEV
As an alternative to setting up a local environment on your computer, you can set up a cloud-based environment using GitPod.io + DDEV. This uses the same configuration as below, but runs it on GitPod's servers and allows editing in the browser-based version of Visual Studio Code.
Set up a local environment using DDEV
When you are ready to set up a local environment on your machine, follow these steps.
Install DDEV
Install DDEV if it's not already installed. To install DDEV, see the DDEV installation documentation.
Clone the Git repository
Clone the Git repository for the Anytown Farmer's Market site. In the directory where you want the cloned repository to live run the following command:
git clone https://github.com/DrupalizeMe/module-developer-guide-demo-site.git
Change directories into the project directory.
cd module-developer-guide-demo-site
Launch DDEV and install required dependencies
Start DDEV from project's top-level directory. You'll use the configuration provided in the project's .ddev/ directory. With DDEV running, you can use Composer to install Drupal core and dependencies:
ddev start
ddev composer install
Install Drupal
Run the installer to set up an empty Drupal installation. This will initialize some things like the database connection information in the site's settings.php file. We'll override this installation in the next step with a backup:
ddev drush site:install -y
Restore the database and files
Use the provided database and public files backups to overwrite the empty Drupal site with a copy of the Anytown Farmer's Market site:
ddev import-db --file=backups/d11.start-here.sql.gz
ddev import-files --source=backups/public_files.tar.gz
ddev drush updatedb -y
ddev drush cr
Login and change the user 1 password
Sign in to the admin account by using a one-time login link generated by Drush and then change the password:
ddev drush user:login
This will output a link you can follow to log in to the site as the admin user.
You should now have a working copy of the Anytown Farmer's Market site. Take a moment to familiarize yourself with the site's architecture including content types, fields, and other settings.
Recap
In this tutorial, we created a copy of the Anytown Farmer's Market site using DDEV as the local development environment. This will serve as a safe place to experiment with code while learning how to author custom Drupal modules.
Further your understanding
- What content types and fields exist in the Anytown Farmer's Market site? How do you think they are used?
- Can you explain how the Anytown Farmer's Market site will be used in this guide? And why?
Additional resources
- DDEV (ddev.readthedocs.io)
- Install Drupal Locally with DDEV (Drupalize.Me)