Installing Drupal on Your Own Computer

Installing Drupal on Your Own Computer esembrat3
Drupal Version

Purpose

A development copy of Drupal on your local computer lets you design and build a site with a few fewer hassles.  It is an excellent place to do testing and code development, but does not support collaboration very well.  For collaborating with stakeholders, you may want to have both a development site on your local computer and a test site on a regular internet connected web hosting solution (e.g. OIT Web Hosting or a departmentally run server).

Potential Uses

  • Testing new patches or major upgrades.
  • Testing out new themes or modules.
  • Module or theme development.
  • Stress-testing a site.
  • Getting familiar with Drupal.

Expert Local Development Guides

How to Set Up a Mac OS X / macOS System for Local Development

How to Set Up a Mac OS X / macOS System for Local Development bwaye3
Drupal Version

This process allows you to set up your Mac as a faux-server for local development.

  1. Download Xcode from the App Store:  https://developer.apple.com/xcode/
  2. Install command line tools: http://osxdaily.com/2014/02/12/install-command-line-tools-mac-os-x/
  3. Install and configure wget: http://coolestguidesontheplanet.com/install-and-configure-wget-on-os-x/

Do note that Drupal 8 requires PHP 7, and only MacOS 10.14+ (Mojave or later) come with PHP 7 – all earlier versions have some form of PHP 5.  If you are running and older version of MacOS, you can either use HomeBrew to try to upgrade PHP, or look at one of the options to install a virtual development environment on your local computer.

How to Use Lando as a Drupal Development Environment

How to Use Lando as a Drupal Development Environment
Category
esembrat3
Drupal Version

What is Lando? From the Lando documentation:

It's a free, open source, cross-platform, local development environment and DevOps tool built on Docker container technology and developed by Tandem. Designed to work with most major languages, frameworks and services, Lando provides an easy way for developers of all skill levels to specify simple or complex requirements for their projects, and then quickly get to work on them.

In simpler terms, it is a container system built on Docker that runs on Windows, MacOS, and Linux, letting you spin up development websites with a minimum technical hassles.  It is just one of many ways to easily set up a Drupal 10 development site for either building a complete new website, doing module development work, or testing third-party modules in a safe "sandbox" environment.

Enabling a Mail Server in Lando

Enabling a Mail Server in Lando
Category
esembrat3
Drupal Version

The Lando Drupal 7 recipe does not come with mail functionality out-of-the-box. However, DrupalEasy has written straight-forward documentation on how to enable server mail functionality.

This is helpful for enabling mail notifications for password resets, trigger/Rules configuration.

Process

  1. Add the following configuration to your .lando.yml recipe:
    proxy:
      mailhog:
        - mail.lemp.lndo.site
    services:
      mailhog:
        type: mailhog
        hogfrom:
          - appserver
  2. Edit mail.lemp.lndo.site to better match, mirror, or apply to your local Lando website.

  3. Run "lando rebuild". Caution should be used when using using the 'rebuild' command, as while most services retain their data during a rebuild, some may not

  4. Running "lando start" will now initialize a Mailhog server, which will siphon all Drupal-generated mail into that inbox.

Lando and Mercury Reader

Lando and Mercury Reader
Category
esembrat3
Drupal Version

Mercury Reader requires an extra php extension outside of what lando's drupal10 recipe typically provides.

Process

Adjust your lando.yml Landofile to include the following:

services:  
  appserver:
    build_as_root:
      - apt-get update -y
      - apt-get install libxslt1-dev -y
      - docker-php-ext-install xsl
      - docker-php-ext-enable xsl

Rebuild your lando environment to install the libraries:

lando rebuild -y

 

Set up lando on Windows 10 for an easy local development environment

Set up lando on Windows 10 for an easy local development environment
Category
afrank30
Drupal Version
  1. First install WSL version 2. You do not need VSCode or Hyper-V and may not even need to install a specific version of Ubuntu (20.04 at the time of writing), as it usually defaults to the latest version.
  2. Next, install Docker Desktop for Windows (on Windows, NOT within the Ubuntu VM).
  3. Then, install lando's .exe from github (on Windows, NOT within the Ubuntu VM).

Starting a Drupal 10 Website with Lando

Starting a Drupal 10 Website with Lando
Category
esembrat3
Drupal Version

The below scenario assumes you have Lando installed on your own machine for local development.

Kickstarting a Drupal 9 website

Install Drupal via composer:

composer create-project drupal-composer/drupal-project:10.x-dev SITENAME --no-interaction

Enter SITENAME and init lando.

cd SITENAME
lando init

During the lando init process:

  • Select the appropriate recipe (drupal9) for lando.
  • Provide the webroot directory (web).
  • Provide a shortcut name for the lando app (your choice and preference).

Once completed, now start up your virtual environment with:

lando start

Lando will kickstart the virtual filesystems in your specified root directory and initialize a locally-hosted database and web server (using Docker).

When you see BOOMSHAKALAKA!, Lando has configured all the environment configurations and is ready to party.

Using Drupal 10 with Lando

Using Drupal 10 with Lando
Category
esembrat3
Drupal Version

Drupal Console, Drush and Lando

Lando provides scaffolding for tools like Drupal Console and Drush.

To use these tools within Lando, just pre-empt your command with lando to make sure it's running within the Lando interface.

For example, to install a new module in Drupal 8 using Drupal Console, use:

lando drupal moi module_name

Or, to clear all caches using Drupal Console, use:

lando drupal cc all

Please see the Lando Drupal 8 documentation for a full list of tools.

Example .lando.yml files for different environments

Example .lando.yml files for different environments
Category
afrank30
Drupal Version

Here are some example .lando.yml files (and associated settings.php files for drupal) of commonly-used configurations.

Drupal 7: Single site

Database code in settings.php

$databases = array (
  'default' => 
  array (
    'default' => 
    array (
      'database' => 'myd7sitedb',
      'username' => 'database',
      'password' => 'database',
      'host' => 'database',
      'port' => '3306',
      'driver' => 'mysql',
      'prefix' => '',
    ),
  ),
);

.lando.yml Code

name: myd7site
recipe: drupal7
config:
  php: '7.3'
  composer_version: 2
  via: 'apache:2.4'
  webroot: .
  database: 'mysql:5.7'
  # note this is just for lando/docker as 'global' install--drush is installed via drupal composer for local site use
  drush: ^8
  xdebug: false
services:
  database:
    creds:
      user: database
      password: database
      database: myd7sitedb
  appserver:
    overrides:
      environment:
        DRUSH_OPTIONS_URI: "https://local.myd7site.gatech.edu"
tooling:
  'lint:php:themes':
    service: appserver
    cmd: /app/vendor/bin/phpcs --standard=phpcs-themes.xml
    description: 'Runs php linter against your custom code. Ex: lando lint:php'
proxy:
  appserver:
    - myd7site.lndo.site
    - local.myd7site.gatech.edu //set in local hosts file

Drupal 7: Multi site

Database code in settings.php

$databases = array (
  'default' =>
    array (
      'default' =>
        array (
          'database' => 'database',
          'username' => 'mysql',
          'password' => 'mysql',
          'host' => 'ic',
          'port' => '3306',
          'driver' => 'mysql',
          'prefix' => '',
        ),
    ),
);

.lando.yml Code

name: multid7
recipe: drupal7
config:
  php: '7.3'
  composer_version: 2
  via: 'apache:2.4'
  webroot: .
  database: 'mysql:5.7'
  # note this is just for lando/docker as 'global' install--drush is installed via drupal composer for local site use
  drush: ^8
  xdebug: false
proxy:
  appserver:
    - cse.lndo.site
    - local.cse.gatech.edu //set in local hosts file
    - ic.lndo.site
    - local.ic.gatech.edu //set in local hosts file
    - scs.lndo.site
    - local.scs.gatech.edu //set in local hosts file
services:
  cse:
    type: mysql:5.7
    appserver:
      overrides:
        environment:
          DRUSH_OPTIONS_URI: "https://local.cse.gatech.edu"
  ic:
    type: mysql:5.7
    appserver:
      overrides:
        environment:
          DRUSH_OPTIONS_URI: "https://local.ic.gatech.edu"
  scs:
    type: mysql:5.7
    appserver:
      overrides:
        environment:
          DRUSH_OPTIONS_URI: "https://local.scs.gatech.edu"

Drupal 9: Single site

Database code in settings.php

$databases['default']['default'] = array (
  'database' => 'myd9db',
  'username' => 'database',
  'password' => 'database',
  'prefix' => '',
  'host' => 'database',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);

.lando.yml Code

name: myd9
recipe: drupal9
config:
  php: '7.3'
  composer_version: 2
  via: 'apache:2.4'
  webroot: .
  database: 'mysql:5.7'
  drush: true
  xdebug: false
tooling:
  'lint:php:themes':
    service: appserver
    cmd: /app/vendor/bin/phpcs --standard=phpcs-themes.xml
    description: 'Runs php linter against your custom code. Ex: lando lint:php'
  drush:
    service: appserver
    env:
     DRUSH_OPTIONS_URI: "https://local.myd9.gatech.edu"
proxy:
  appserver:
    - myd9.lndo.site
    - local.myd9.gatech.edu // set in local hosts file
services:
  database:
    creds:
      user: database
      password: database
      database: myd9db

Symfony 4

.lando.yml Code

name: samplesymfony4app
recipe: symfony
config:
  symfony: '4'
  php: '7.3'
  via: 'apache:2.4'
  webroot: public
  database: mysql:5.7
  services:
    database:
        creds:
            user: database
            password: database
            database: gradcc

Symfony 5

.lando.yml Code

name: samplesymfony5app
recipe: symfony
config:
  php: '7.3'
  via: 'apache:2.4'
  webroot: public
  database: mysql:5.7
  services:
    database:
        creds:
            user: database
            password: database
            database: symfony5db

Simple LAMP stack for PHP

.lando.yml Code

name: myphp
recipe: lamp
config:
  php: '7.4'
  via: 'apache:2.4'
  composer_version: '2'
  webroot: public
  database: mysql:5.7
  services:
    database:
        creds:
            user: database
            password: database
            database: myphpdb
  proxy:
    appserver:
      - myphp.lndo.site
      - local.myphp.gatech.edu // set in local hosts file