Drupal VM is one of the most flexible and powerful local development environments for Drupal, but one the main goals of the project is to build a fully-functional Drupal 8 site quickly and easily without doing much setup work. The ideal would be to install Vagrant, clone or download the project, then run
vagrant up. A few minutes later, you'd have a Drupal 8 site ready for hacking on!
In the past, you always had to do a couple extra steps in between, configuring a
drupal.make.yml file and a
config.yml file. Recently, thanks in huge part to Oskar Schöldström's herculean efforts, we achieved that ideal by switching from defaulting to a Drush make-based workflow to a Composer-based workflow (this will come in the 3.1.0 release, very soon!). But it wasn't without trial and tribulation!
Before we switched the default from Drush make to Composer, I wanted to get initial build times down so users didn't have to wait for an excruciatingly long time to download Drupal. At first, using all the defaults, it took twice as long to build a Drupal site from a
composer.json file or using drupal-project as it did to build the Drupal site from an equivalent make file. The main reason is that Composer spends a lot more time than Drush in resolving project dependencies (recursively reading all
composer.json files and downloading all the required projects into the
I thought I'd share some of the things we learned concerning speeding up Composer installs and updates for Drupal (and other PHP projects) in a blog post, so the tips aren't buried in issues in Drupal VM's issue queue:
prestissimo is a Composer plugin that enables parallel installations. All you have to do is
composer global require "hirak/prestissimo:^0.3", and all
composer install commands will use parallel package downloads, greatly speeding up the initial installation of Drupal.
For Drupal VM, the Drupal download time went from 400 seconds to 166 seconds—more than 2x faster for the Composer installation!
Make sure XDebug is disabled
This one should be rather obvious, but many times, developers leave XDebug enabled on the CLI, and this slows down Composer substantially—sometimes making installs take 2-4x longer! Make sure
0 in Drupal VM's
config.yml if you have
xdebug installed in the
(If using Vagrant) Use
Many Vagrant power users already use
vagrant-cachier with their VMs to cache
yum packages so rebuilds are quicker (you don't have to re-download frequently-installed packages anymore); but to use it with Composer, you need add one extra bit of configuration in your
... any other cachier configuration ...
# Cache the composer directory.
config.cache.enable :generic, :cache_dir => '/home/vagrant/.composer/cache'
We can't use
vagrant-cachier's built-in Composer bucket, because PHP isn't preinstalled on the base boxes Drupal VM uses. So we use a
:generic bucket instead, and manually point it at the Composer cache directory inside the VM.
Things that didn't seem to help
- Shallow Git clones: Some people suggested using shallow Git clones (e.g. following this Composer PR), but it didn't make a measurable difference.
"minimum-stability": "dev": In the past, setting
devcould speed things up a bit while Composer sorts out the dependency tree (see this post). It seems to not have any measurable impact in this case, though.
- There are still some other areas ripe for improvement, too—for example, the
drupal-packagistproject may be able to improve it's caching infrastructure to greatly speed up download times.
Please let me know if there are other tips and tricks you may have that can help speed up Composer—we've almost hit the same build times with Composer that we hit with Drush make files, but make files are still slightly faster.