Dev environment with docker4drupal
This repository has been set up to work with docker compose. You need docker and docker compose to use the commands below. You dont need to use docker.
# start up containers
docker compose up -d
# log in to php container
docker compose exec php sh
# switch to laravel folder
cd laravel
# install dependencies
composer install
# cp env.dev and configure
# verify db configs
cp .env.dev .env
# run initialisation commands
php artisan migrate
php artisan db:seed --class=DatabaseSeeder
php artisan db:seed --class=UsersTableSeeder
php artisan key:generate
# or you can run this (it will recreate the database each time)
composer build
# and this command to setup demo users and members for dev (must run after composer build)
composer dev
# register for a google recaptcha site key and secret here
https://www.google.com/recaptcha/admin/create
# in the domains field enter the following
sita-membership.docker.localhost
# once received, add your google recaptcha environment variables to laravel/.env
GOOGLE_RECAPTCHA_SITE_KEY=YOUR_GOOGLE_RECAPTCHA_SITE_KEY
GOOGLE_RECAPTCHA_SECRET_KEY=YOUR_GOOGLE_RECAPTCHA_SECRET_KEY
# for scheduled events use the following command to process them
php artisan schedule:run
- Once installed you can access the dev site on:
sita-membership.docker.localhost:8000
- Click "Register" and register a new account then use it to log in.
- OR - run
composer dev
to set up test accounts
This will create test accounts and dummy data for local dev.
composer dev
# [email protected] - user with no roles
# [email protected] - user with executive role
# [email protected] - user with coordinator role
# [email protected] - user with admin role
# All accounts use "password" as its password
We have linting for PHP and JS which should take care of most things. Please be respectful when adding code comments and responding to feedback.
# run in php container
composer lint # shows warnings and errors
composer lint_ci # shows only errors
composer format # tries to fix php problems
# run in node container
npm run lint # shows warnings and tries to fix
npm run format # tries to fix js/vue problems
# To take a backup run the following command
php artisan backup:run
# to clean out old backups
php artisan backup:clean
To display them run the following comand to create a symlink
php artisan storage:link
To run your dev with SSL support use the following command
# start containers
docker compose -f docker-compose.yml -f docker-compose.ssl.yml up -d
# stop containers
docker compose -f docker-compose.yml -f docker-compose.ssl.yml stop
Update the laravel .env file to the following values as needed
- local - for local development
- demo - for a uat or demo site (demo users cannot be deleted)
- production - for production site
Ensure that the following commands are run on a cron see https://laravel.com/docs/10.x/scheduling#running-the-scheduler
# run every minute - for scheduled tasks
php artisan schedule:run
# run every 5 minutes - for running queues
php artisan queue:work database --tries=1 --max-time=30 --stop-when-empty
Also set APP_ENV=production and GOOGLE_ANALYTICS_GA4. This will ensure Google Analytics works correctly.
Set MAIL_BACKUPS_TO_ADDRESS to be notified of backup statuses.
Also if using SSL update the following variables accordingly in .env. Here example.com is used as an example domain
DOMAIN=example.com
[email protected]
CERT_RESOLVER=letsencrypt
# clear database and re-run migrations
php artisan migrate:fresh
# create a new model, controller and migration called Member
php artisan make:model -mrc Member
# start up dev environment
docker compose up -d
# stop environment
docker compose stop
# delete everything and start in a clean environment
docker compose down -v
# check logs
docker compose logs -f
# check logs for specific container
docker compose logs -f php
# log into php container (this will allow use php artisan)
docker compose exec php sh
# run tests
./vendor/bin/pest
# create pest test
php artisan make:test UserTest --pest
Use bash aliases in your local dev
# docker compose aliases
alias dc="docker compose"
alias dup="docker compose up -d"
alias dlup="docker compose up -d && docker compose logs php"
alias dphp="docker compose exec php sh"
alias dnode="docker compose exec node bash"
alias dlnode="docker compose logs -f node"
alias dstop="docker compose stop"