Just enough of a local Drupal development environment
In preparation for Agaric's migration training at DrupalCon Seattle, we've seen again that getting a development environment suitable for working on Drupal 8 with Composer is a big road block. For that reason, here are instructions for getting it all going, suitable for our training or for working on Drupal in a code sprint, with only one hard requirement: PHP.
Getting a local development going is a problem for everyone, including programmers and people who should be skilled at this. Vagrant and DrupalVM were created to make identical development environments work on any computer. Unfortunately, that's more a pipe dream than a promise, as our own experiences and support requests we've received can attest,
Docker is another attempt to make local development match production environments, and a newer generation of Drupal-adjacent development workflow tools, such as DDEV, Lando, Docksal, and Humpback, build on it. Using an online development environment is also an option, but has too much reliance on working WiFi for conference situations.
The goal is any Drupal development environment—any of the above or anything else—where you can go to your project root directory in a terminal and type, say, composer update and have If you don't have a local development environment of any kind, here is the minimalist approach. All the steps start with opening your terminal.
Quick and dirtiest
mkdir ~/sandbox cd ~/sandbox
Now copy the four commands beginning with php from the top of Composer's quick install documentation. Paste them into the terminal in your sandbox directory. It's best to use Composer's commands, which they update to verify the hash after every release, which is why we don't have the commands for you to copy here. Once that is done, continue:
php composer.phar create-project drupal-composer/drupal-project:8.x-dev just-drupal --no-interaction cd just-drupal php ../composer.phar require drush/drush
If that works, you're good to go!
To use Drush:
To start PHP's built-in webserver and see the site, use:
php web/core/scripts/drupal quick-start standard
If it works, it will install Drupal with the Standard installation profile and log you in, opening your local site in your browser. Your terminal window, meanwhile, is dedicated to running the server. Open a new tab in your terminal, at the same location (
cd ~/sandbox/just-drupal in our example) to be able to run more composer or other commands.
In the migration training for instance we have people use composer to get the code for the address module, so from
~/sandbox/just-drupal in our example we would run:
php ../composer.phar require drupal/address
And to enable the address module downloaded just above:
vendor/bin/drush en address
Note that the site must be 'running' with the
php web/core/scripts/drupal quick-start command you can run at any time to get things started and log back in (don't worry if you get "Access Denied" while also seeing the administration menu (starting with "Manage" at the top left of your screen; this just means you were already logged in).
This minimalist approach might not work either for your computer! If it doesn't, there may be more PHP things to install. For instance, if you run into an error about SQLite, you may need to enable or install SQLite with PHP first. We'll update this blog post with further fixes and workarounds as they come up for our content migration or other training students.
Quick and just slightly polished
You may have noticed that typing
php ../composer.phar and
vendor/bin/drush is pretty ugly. This can be fixed while retaining essentially the same setup as above by installing Composer globally (for GNU/Linux and Mac OS X, or with the Windows installer for Microsoft Windows) and installing the Drush launcher. Once you've done that, you'll be able to use
composer instead of
php ../composer.phar and
drush instead of
Warning and reminder
This is for a local development environment or sandbox testing site only! PHP's built-in server, which is relied upon in the above, is absolutely not intended to be used in production environments. Neither, for Drupal, is SQLite, which we're also using. To repeat, this is not meant to be used live!
Updated. I knew it was out there, but didn't find this when i started writing. This is very similar in approach to an article last year by MediaCurrent celebrating this capability coming to Drupal. The main difference is that in our blog post here we use the Composer template for Drupal 8 projects. This avoids having Git as a requirement (but you should always develop by committing to Git!) and also starts with a best-practices composer setup. Distributions like Drutopia take the same approach.