DEV Community

nabbisen
nabbisen

Posted on

Updating Drupal with Composer

Summary

All the steps to update Drupal 8 under PHP Composer are:

$ cd <drupal-dir>

$ # check outdated php modules
$ php-7.3 /usr/local/libexec/composer.phar outdated "drupal/*"
$ # update app
$ php-7.3 /usr/local/libexec/composer.phar update

$ # prepare symbolic link of php executable
# ln -s /usr/local/bin/php-7.3 /usr/local/bin/php

$ # update database
$ ./vendor/bin/drush updatedb
$ # clear cache
$ ./vendor/bin/drush cr

$ # check the whole result
$ ./vendor/bin/drush status
$ # remove symbolic link of php executable
# rm /usr/local/bin/php
Enter fullscreen mode Exit fullscreen mode

Points

  1. It is necessary to create php symbolic link for php-7.x executable in order to avoid the error "env: php: No such file or directory" at running drush.
  2. Don't use pkg_add drush because drush/drush is already included as Drupal's "require" in composer.json.
  3. Checking drush status finally is surely useful.

Tutorial

Case

8.7.7 -> 8.7.8

Get started

Go to the Drupal directory:

$ cd <drupal-dir>
Enter fullscreen mode Exit fullscreen mode

Update app

First, check which modules of Drupal core are outdated:

$ php-7.3 /usr/local/libexec/composer.phar outdated "drupal/*"
Enter fullscreen mode Exit fullscreen mode

The result was:

drupal/core 8.7.7 8.7.8 Drupal is an open source content management platform powering millions of ...
Enter fullscreen mode Exit fullscreen mode

Besides, the command to check the overall modules is:

$ php-7.3 /usr/local/libexec/composer.phar outdated
Enter fullscreen mode Exit fullscreen mode

The result was:

behat/mink-selenium2-driver             dev-master 8684ee4 dev-master 3ab9f31 Selenium2 (WebDriver...
dflydev/dot-access-data                 v1.1.0             v2.0.0             Given a deep data st...
doctrine/annotations                    v1.7.0             v1.8.0             Docblock Annotations...
drupal/core                             8.7.7              8.7.8              Drupal is an open so...
grasmash/yaml-expander                  1.4.0              2.0.0              Expands internal pro...
instaclick/php-webdriver                1.4.5              1.4.6              PHP WebDriver for Se...
league/container                        2.4.1              3.3.0              A fast and intuitive...
phar-io/manifest                        1.0.1              1.0.3              Component for readin...
phar-io/version                         1.0.1              2.0.1              Library for handling...
phpspec/prophecy                        1.8.1              1.9.0              Highly opinionated m...
phpunit/php-code-coverage               5.3.2              7.0.8              Library that provide...
phpunit/php-file-iterator               1.4.5              2.0.2              FilterIterator imple...
phpunit/php-timer                       1.0.9              2.1.2              Utility class for ti...
phpunit/php-token-stream                2.0.2              3.1.1              Wrapper around PHP's...
phpunit/phpunit                         6.5.14             8.4.0              The PHP Unit Testing...
phpunit/phpunit-mock-objects            5.0.10             6.1.2              Mock Object library ...
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
sebastian/comparator                    2.1.3              3.0.2              Provides the functio...
sebastian/diff                          2.0.1              3.0.2              Diff implementation
sebastian/environment                   3.1.0              4.2.2              Provides functionali...
sebastian/global-state                  2.0.0              3.0.0              Snapshotting of glob...
sebastian/resource-operations           1.0.0              2.0.1              Provides a list of P...
squizlabs/php_codesniffer               3.4.2              3.5.0              PHP_CodeSniffer toke...
symfony-cmf/routing                     1.4.1              2.1.0              Extends the Symfony2...
symfony/config                          v3.4.31            v4.3.4             Symfony Config Compo...
symfony/console                         v3.4.31            v4.3.4             Symfony Console Comp...
symfony/css-selector                    v3.4.31            v4.3.4             Symfony CssSelector ...
symfony/debug                           v3.4.31            v4.3.4             Symfony Debug Component
symfony/dependency-injection            v3.4.31            v4.3.4             Symfony DependencyIn...
symfony/dom-crawler                     v3.4.31            v4.3.4             Symfony DomCrawler C...
symfony/event-dispatcher                v3.4.31            v4.3.4             Symfony EventDispatc...
symfony/filesystem                      v3.4.31            v4.3.4             Symfony Filesystem C...
symfony/finder                          v3.4.31            v4.3.4             Symfony Finder Compo...
symfony/http-foundation                 v3.4.31            v4.3.4             Symfony HttpFoundati...
symfony/http-kernel                     v3.4.31            v4.3.4             Symfony HttpKernel C...
symfony/phpunit-bridge                  v3.4.31            v4.3.4             Symfony PHPUnit Bridge
symfony/process                         v3.4.31            v4.3.4             Symfony Process Comp...
symfony/routing                         v3.4.31            v4.3.4             Symfony Routing Comp...
symfony/serializer                      v3.4.31            v4.3.4             Symfony Serializer C...
symfony/translation                     v3.4.31            v4.3.4             Symfony Translation ...
symfony/validator                       v3.4.31            v4.3.4             Symfony Validator Co...
symfony/yaml                            v3.4.31            v4.3.4             Symfony Yaml Component
twig/twig                               v1.42.3            v2.12.0            Twig, the flexible, ...
typo3/phar-stream-wrapper               v2.1.2             v3.1.2             Interceptors for PHP...
vlucas/phpdotenv                        v2.6.1             v3.6.0             Loads environment va...
webflo/drupal-core-require-dev          8.7.7              8.7.8              require-dev dependen...
zaporylie/composer-drupal-optimizations 1.1.0              1.1.1              Composer plugin to i...
zendframework/zend-diactoros            1.8.7              2.1.3              PSR HTTP Message imp...
Enter fullscreen mode Exit fullscreen mode

Well, update them actually:

$ php-7.3 /usr/local/libexec/composer.phar update
Enter fullscreen mode Exit fullscreen mode

* Note: Adding --dry-run option to the above enables you to check what will be updated without actually updating.

The result was:

> DrupalProject\composer\ScriptHandler::checkComposerVersion
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 7 updates, 0 removals
  - Updating zaporylie/composer-drupal-optimizations (1.1.0 => 1.1.1): Downloading (100%)         
  - Updating phpspec/prophecy (1.8.1 => 1.9.0): Downloading (100%)         
  - Updating squizlabs/php_codesniffer (3.4.2 => 3.5.0): Downloading (100%)         
  - Updating instaclick/php-webdriver (1.4.5 => 1.4.6): Downloading (100%)         
  - Updating doctrine/annotations (v1.7.0 => v1.8.0): Downloading (100%)         
  - Updating drupal/core (8.7.7 => 8.7.8): Downloading (100%)         
  - Updating webflo/drupal-core-require-dev (8.7.7 => 8.7.8)
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
Writing lock file
Generating autoload files
  - .csslintrc (https://git.drupalcode.org/project/drupal/raw/8.7.8/.csslintrc): Downloading (connectiDownloading (100%)         
  - .editorconfig (https://git.drupalcode.org/project/drupal/raw/8.7.8/.editorconfig): Downloading (coDownloading (100%)         
  - .eslintignore (https://git.drupalcode.org/project/drupal/raw/8.7.8/.eslintignore): Downloading (coDownloading (100%)         
  - .eslintrc.json (https://git.drupalcode.org/project/drupal/raw/8.7.8/.eslintrc.json): Downloading (Downloading (100%)         
  - .gitattributes (https://git.drupalcode.org/project/drupal/raw/8.7.8/.gitattributes): Downloading (Downloading (100%)         
  - .ht.router.php (https://git.drupalcode.org/project/drupal/raw/8.7.8/.ht.router.php): Downloading (Downloading (100%)         
  - .htaccess (https://git.drupalcode.org/project/drupal/raw/8.7.8/.htaccess): Downloading (connectingDownloading (100%)         
  - index.php (https://git.drupalcode.org/project/drupal/raw/8.7.8/index.php): Downloading (connectingDownloading (100%)         
  - robots.txt (https://git.drupalcode.org/project/drupal/raw/8.7.8/robots.txt): Downloading (connectiDownloading (100%)         
  - sites/default/default.services.yml (https://git.drupalcode.org/project/drupal/raw/8.7.8/sites/default/default.services.yml): Downloading (100%)         
  - sites/default/default.settings.php (https://git.drupalcode.org/project/drupal/raw/8.7.8/sites/default/default.settings.php): Downloading (100%)         
  - sites/development.services.yml (https://git.drupalcode.org/project/drupal/raw/8.7.8/sites/development.services.yml): Downloading (100%)         
  - sites/example.settings.local.php (https://git.drupalcode.org/project/drupal/raw/8.7.8/sites/example.settings.local.php): Downloading (100%)         
  - sites/example.sites.php (https://git.drupalcode.org/project/drupal/raw/8.7.8/sites/example.sites.php): Downloading (100%)         
  - update.php (https://git.drupalcode.org/project/drupal/raw/8.7.8/update.php): Downloading (connectiDownloading (100%)         
  - web.config (https://git.drupalcode.org/project/drupal/raw/8.7.8/web.config): Downloading (connectiDownloading (100%)         
> DrupalProject\composer\ScriptHandler::createRequiredFiles
Enter fullscreen mode Exit fullscreen mode

Update DB

Drush requires php executable.
So let's create it as a symbolic link:

# ln -s /usr/local/bin/php-7.3 /usr/local/bin/php
Enter fullscreen mode Exit fullscreen mode

Then, update the database:

$ ./vendor/bin/drush updatedb
Enter fullscreen mode Exit fullscreen mode

The result was:

 [success] No pending updates.
Enter fullscreen mode Exit fullscreen mode

Well, table definitions are sometimes changed here.

Next, clear cache:

$ ./vendor/bin/drush cr
Enter fullscreen mode Exit fullscreen mode
 [success] Cache rebuild complete.
Enter fullscreen mode Exit fullscreen mode

Validate

The things are almost done.

Check the whole status at last:

$ ./vendor/bin/drush status
Enter fullscreen mode Exit fullscreen mode

The result was:

 Drupal version   : 8.7.8
 Site URI         : http://default
 DB driver        : mysql
 DB hostname      : 127.0.0.1
 DB port          : 3306
 DB username      : <dbuser>
 DB name          : <database>
 Database         : Connected
 Drupal bootstrap : Successful
 Default theme    : bartik
 Admin theme      : bartik
 PHP binary       : /usr/local/bin/php-7.3
 PHP config       : /etc/php-7.3.ini
 PHP OS           : OpenBSD
 Drush script     : /var/www/<drupal-dir>/vendor/drush/drush/drush
 Drush version    : 9.7.1
 Drush temp       : /tmp
 Drush configs    : /var/www/<drupal-dir>/vendor/drush/drush/drush.yml
                    /var/www/<drupal-dir>/drush/drush.yml
 Install profile  : standard
 Drupal root      : /var/www/<drupal-dir>/drupal/web
 Site path        : sites/default
 Files, Public    : sites/default/files
 Files, Temp      : /tmp
Enter fullscreen mode Exit fullscreen mode

"Drupal version : 8.7.8" was got. O.K.

Clean up

Remove the symbolic link at last:

# rm /usr/local/bin/php
Enter fullscreen mode Exit fullscreen mode

Done

Now everything seems fine :)

available updates

status report

Reference

Top comments (2)

Collapse
 
teknorah profile image
Norah Medlin

It might be worth noting that if you use a dockerized environment with composer and drush installed globally, you can run simpler commands like this:

composer update
drush entup
drush updb
drush cr

Collapse
 
nabbisen profile image
nabbisen

Hi Norah, Thank you for your comments.
I think you're totally right.
I have used OpenBSD, however, as my primary and lovely environment for years 😅
Well, I'm interested in dockerized environments and I'll try it. Thank you 😉