Set up Demo Site with Views and Content for Drupal 8 and Drupal 9

Last updated May 7, 2020

To follow along with our Drupal 8 Views tutorials, set up a Drupal 8 site loaded with our 4 custom views and baseball stats content that will make querying in Views a bit more interesting and meaningful.

By the end of this tutorial, you should choose a solution and follow the instructions for creating a Drupal site loaded with our starting point content and views.

Goal

  • Set up a Drupal 8 site with a starting point containing baseball stats content and 4 custom views.

Prerequisites

  • Ability/permissions to download software to your local machine.
  • To use DDEV, you should have DDEV installed (which has its own set of prerequisites, such as Docker). See DDEV Documentation and follow the installation instructions for your operating system. You should also be comfortable using the command line to navigate the file system and run commands. See Command Line Basics if needed.

No-install alternative

  • Feel free to use our Create a Sandbox button, which will create a Drupal application instance via Tugboat in a new browser window. Use it to walk-through the tutorials in this series. Learn more in this blog post: Sandboxes Now Available for Drupal 8 Views Tutorials.

Recommendation: Use DDEV to install Drupal

We'll use DDEV to install Drupal 8 and import a database starting point that contains the content and views for our Views in Drupal 8 tutorials. We've copied instructions from the Drupal Official Docs Local Development Guide in the following steps.

Exercise: Install Drupal with special content and configuration

Install DDEV

To use DDEV to install Drupal, you'll need to install DDEV and its prerequisites, most importantly, Docker.

Execute the following command to install DDEV:

curl -L https://raw.githubusercontent.com/drud/ddev/master/scripts/install_ddev.sh | bash

For more information, view the DDEV Documentation and follow the installation instructions for your operating system.

Create a new Drupal application

Choose a location for your local Drupal site, then run the following commands to create a new Drupal application via Composer. (Replace my-site-name with whatever you want to call your project directory). Or, use the ddev composer command if you don't have Composer installed on your machine.

The export command is optional and makes it easier to copy and paste commands in this step and the next. You could skip the export line and replace $SITE_NAME with the name of your directory, i.e. my-site-name.

# Replace my-site-name!
export SITE_NAME=my-site-name
composer create-project drupal/recommended-project $SITE_NAME
cd $SITE_NAME

This will create a new directory and populate it with Drupal (and its dependencies).

Configure environment to serve your Drupal application

You now have a Drupal codebase. Next, you will need to configure your local development environment to serve that new codebase. At minimum, this requires creating a new database for Drupal and configuring the web server to serve Drupal content at a particular URL.

Run the following command (assumes DDEV):

ddev config --docroot web --project-name $SITE_NAME --project-type drupal8

Alternatively, type ddev config and it will walk you through the options, step-by-step.

This will configure your new Drupal application to work with DDEV and will store the generated configuration in a new .ddev subdirectory.

Next, start the DDEV container:

ddev start

You now have a web server and database server configured and running.

Create a new directory in your project called db-dumps

You can use whatever name you want, but if you do, substitute your directory name for db-dumps in the following steps. This is where we'll store database backup files.

mkdir db-dumps

Download our database starting point

Database starting point.

Select the Download button from that page and save the file to your project's db-dumps directory.

Import the database with ddev's import-db command

In a Terminal window, navigate to the root of your project and run the following command:

ddev import-db --src=db-dumps/START-d8-views.sql.gz

Get the local URL for your site

Run ddev launch and DDEV will open up the local site URL in your browser. (Run ddev describe to see your site's URL and other connection information.)

Log in

Log in with username: admin; password: admin.

You are now ready to follow along with any of our Views: Create Lists with Drupal tutorials.

Recap

In this exercise, we installed Drupal and imported a starting-point database with content and Views. We will be using this as a starting point for the tutorials in Views: Create Lists with Drupal.

Further your understanding

  • Do you have a documented, repeatable, and reliable process for setting up a local development environment with Drupal? There are many options to choose from. Take the time to find a solution that works best for your operating system, use case, and knowledge base.

Additional resources