Learning with DrupalXpert

Guide through the essential steps to set up, understand, and begin Drupal development.

Environment Setup

Setting up a reliable and efficient local development environment is critical for Drupal development. In this guide, we’ll walk you through each step to configure your environment with DDEV and Composer, ensuring a smooth and optimized experience.

Prerequisites

Before getting started, ensure the following tools are installed on your machine:

  • DDEV: A Docker-based tool that simplifies local development and automates configurations specific to Drupal. Install DDEV
  • Composer: A dependency manager for PHP, used for installing and managing Drupal libraries and modules. Install Composer

Setting Up the Environment

Once you have installed DDEV and Composer, follow these steps to set up your local development environment:

  1. Clone the Project Repository

    To start, clone the project’s repository to your local machine. This will pull down all the project files.

              
    git clone https://github.com/DrupalXpert/base
    cd dx-project-base

    Tip: Ensure you have Git installed on your machine. If not, download Git and follow the instructions.

  2. Initialize the DDEV Environment

    Next, start DDEV within the project directory. This command initializes the Docker environment with configurations specific to your project’s settings.

              
    ddev start

    Troubleshooting: If you encounter issues with DDEV, ensure Docker is running and try running ddev restart to reinitialize the environment.

  3. Install Dependencies with Composer

    Once DDEV is running, use Composer to install all required dependencies for Drupal, including modules and libraries. This step is essential for setting up your project’s codebase correctly.

              
    ddev composer install

    Note: Composer manages dependencies defined in the composer.json file, making it easier to keep your libraries up to date.

  4. Install Drupal

    Now, use Drush (the Drupal shell tool) to install Drupal. This command will set up Drupal with a basic configuration and create an admin user.

              
    ddev drush site:install --account-name=admin --account-pass=admin -y

    Configuration Tip: Use a strong password for production environments. For local development, you can keep it simple but change it in production for security.

  5. Launch the Drupal Site

    Once Drupal is installed, use DDEV to launch your site in the browser. This will open a local URL (usually https://dx-project-base.ddev.site) where you can see your Drupal site in action.

              
    ddev launch

    Note: DDEV generates a secure local URL with HTTPS, which is helpful for testing site functionalities that require HTTPS.

Initial Configuration Steps

After launching your site, consider making the following initial configurations:

  • Enable Development Modules: Modules like devel and stage_file_proxy can streamline development. Use the following commands to enable them:
              
    ddev drush en devel stage_file_proxy -y
  • Configure Error Reporting: To see detailed error messages, set error reporting to show all messages in admin/config/development/logging on your Drupal site.
  • Enable Caching for Development: In development, disable render caching for real-time feedback on changes. You can configure this in settings.local.php.

Troubleshooting Common Issues

If you encounter issues during setup, here are some common problems and solutions:

  • DDEV Startup Errors: Ensure Docker is running and that you have allocated enough memory. Restart Docker and try ddev restart.
  • Composer Memory Limit Errors: If Composer encounters a memory limit error, try increasing memory allocation or running:
              
    COMPOSER_MEMORY_LIMIT=-1 ddev composer install
  • Drupal Installation Issues: Clear DDEV caches with ddev drush cr or restart DDEV if installation fails.

Next: Git Workflow Basics

Git Workflow Basics

Our Git workflow follows these branch types:

  • main: Stable production branch.
  • develop: Active development branch.
  • feature/: Branches for new features.
  • release/: Branches for preparing production releases.
  • hotfix/: Branches for urgent production fixes.

Workflow Steps

1. Feature Development

  1. Create a new feature branch from develop:
              
    git checkout develop
    git checkout -b feature/feature-name
  2. Work on your feature, commit changes as needed.
  3. Merge back into develop when the feature is complete:
              
    git pull origin develop
    git push
  4. Create a Merge/Pull Request with the feature.

Practical Exercises

Hands-on exercises to reinforce key Drupal concepts and workflows. You'll work through tasks like:

  • Creating content types and fields
  • Developing custom modules and themes
  • Managing user roles and permissions
  • Implementing configuration management

Development Tools

Our toolkit includes:

  • Code Formatter:
              
    ddev phpcbf
  • Code Sniffer:
              
    ddev phpcs
  • PHPStan for static analysis:
              
    ddev phpstan
  • Twig Code Sniffer:
              
    ddev twigcs
  • Configuration Export:
              
    ddev cex
  • Configuration Import:
              
    ddev cim
  • Cache Rebuild:
              
    ddev cr

Starting a Project

Follow these steps to get started with a new DrupalXpert project:

  1. Clone the project repository.
  2. Set up your DDEV environment and dependencies.
  3. Familiarize yourself with the project's README and guidelines.
  4. Use our Git workflow for feature development, bug fixes, and releases.

Community and Support

Join our DrupalXpert community for ongoing support, FAQs, and peer discussions:

Previous: Starting a Project