updating drupal using composer

date: fri 14 jun 24
tags: tech

in the past i have manually updated drupal but it is quite labour intensive so the best way to do it is with composer

i have tried to use composer in the past but have had trouble getting it working

i think the problems were being caused by trying to run it from my home directory rather than my drupal directory

to summarise:

download it:

curl -sS https://getcomposer.org/installer -o composer-setup.php

check the hashing is ok:

HASH=`curl -sS https://composer.github.io/installer.sig`

echo $HASH

php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

set it up:

php composer-setup.php --install-dir=/usr/local/bin --filename=composer

try running it to check it works:


once it is working ok you can navigate to your drupal directory (typically /var/www/html/drupal )

cd /var/www/html/drupal


composer update

composer will do all the 'heavy lifting' regarding the update - one this is done you will need to run the https://yoursite.com/update.php script to update the database

all done

(it's a good idea to back up the drupal directory and the drupal database prior to doing any update)