To follow along with our Drupal Views tutorials, set up a Drupal 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 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 Views Tutorials. (Note: the sandbox has been updated to Drupal 9.)
Recommendation: Use DDEV to install Drupal
We'll use DDEV to install Drupal and import a database starting point that contains the content and views for our Views in Drupal tutorials. We've copied instructions from the Drupal Official Docs Local Development Guide in the following steps.
Watch: Set up Demo Site with Views and Content
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.
Go to the DDEV installation docs and follow the specific steps to install DDEV-Local for your computer's 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 create
command if you don't have Composer installed on your machine.
Note: 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
.
If you have Composer installed on your machine:
# Replace my-site-name!
export SITE_NAME=my-site-name
composer create-project drupal/recommended-project $SITE_NAME
cd $SITE_NAME
If you don't have Composer installed on your machine:
# Replace my-site-name!
mkdir my-site-name
cd my-site-name
ddev config --project-type=drupal9 --docroot=web --create-docroot
ddev start
ddev composer create "drupal/recommended-project"
Then, skip the next step (since you already will have run ddev config
).
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 drupal9
Or enter ddev config
and it will walk you through the options.
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
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-d9-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.)
If you notice any un-themed pages, clear all caches (admin/config/development/performance).
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
- DDEV: System Requirements and Installation (ddev.readthedocs.io)
- DDEV: Drupal 9 Quickstart (ddev.readthedocs.io)
- Development Environments (Drupalize.Me)