Published: June 21, 2024
A bash script to set up Drupal for local development using DDEV
Last week I wrote about how to set up Drupal for core contributing using DDEV. This week I decided to write a bash script so I wouldn't have to remember what I did, it would "just work".
Thanks to Code Enigma for sponsoring the time to work on these type things. I hope this knowledge is beneficial to others and encourages more Drupal core contributions.
First create a file called setup-drupal.sh
and place that "somewhere" on your computer. I have it in a folder called /Users/markconroy/projects/drupal-contrib/
.
Then create the directory you want to install core for contribution into. I use /Users/markconroy/projects/drupal-contrib/drupal-core/
Then, using terminal, cd
to that drupal-core
directory and run the bash script from there, like so bash /path/to/the/setup-drupal.sh
.
Viola!
#!/bin/bash
set -x
# Configure the DDEV project
ddev config --project-type=drupal --php-version=8.3 --docroot=web
# Start the DDEV project
ddev start
# Create a new Drupal project
ddev composer create drupal/recommended-project:^11.x-dev
# Navigate into the web directory and remove all files
cd web
rm -rf *
rm -f .*
# Clone the Drupal project
git clone https://git.drupalcode.org/project/drupal.git .
# Navigate back to the project root
cd ..
# Update the DDEV configuration
ddev config --update
# Restart the DDEV project
ddev restart
# Require Drush using Composer
ddev composer require drush/drush
# Install the Drupal site using Drush
ddev drush site:install --account-name=admin --account-pass=admin -y
# Generate a one-time login link for the Drupal site
ddev drush uli
# Print the current directory
pwd
# Edit ./web/autoload.php to change '/vendor/autoload.php' to '../../vendor/autoload.php
sed -i '' 's/\/vendor\/autoload.php/..\/..\/vendor\/autoload.php/g' web/autoload.php
# Launch the Drupal site in a web browser
ddev launch