This site requires JavaScript to be enabled
An updated version of this article is available

Drupal on Pantheon (Build a site with Composer)

244 views

29.0 - Last modified on 09-30-2025 Revised by Shelby Shone

28.0 - Last modified on 09-23-2025 Revised by David Baniszewski

27.0 - Last modified on 08-11-2025 Revised by Shelby Shone

26.0 - Last modified on 08-07-2025 Revised by David Baniszewski

25.0 - Last modified on 08-07-2025 Revised by Shelby Shone

24.0 - Last modified on 06-02-2025 Revised by David Baniszewski

23.0 - Last modified on 06-02-2025 Revised by Shelby Shone

22.0 - Last modified on 05-27-2025 Revised by David Baniszewski

21.0 - Last modified on 05-22-2025 Revised by David Baniszewski

20.0 - Last modified on 02-03-2025 Revised by Michael Arsenault

19.0 - Last modified on 02-03-2025 Revised by Robert Hopkins

18.0 - Last modified on 02-03-2025 Revised by David Baniszewski

17.0 - Last modified on 02-03-2025 Revised by Sussan Dehghan-Kavoosi

16.0 - Last modified on 02-03-2025 Revised by David Baniszewski

15.0 - Last modified on 02-03-2025 Revised by David Baniszewski

14.0 - Last modified on 02-03-2025 Revised by David Baniszewski

13.0 - Last modified on 02-03-2025 Revised by David Baniszewski

12.0 - Last modified on 02-03-2025 Revised by Lauren Kuza

11.0 - Last modified on 02-03-2025 Revised by David Baniszewski

8.0 - Last modified on 02-03-2025 Revised by David Baniszewski

7.0 - Last modified on 02-03-2025 Revised by David Baniszewski

6.0 - Last modified on 02-03-2025 Revised by David Baniszewski

5.0 - Last modified on 02-03-2025 Revised by David Baniszewski

4.0 - Last modified on 02-03-2025 Revised by David Baniszewski

3.0 - Last modified on 02-03-2025 Revised by David Baniszewski

2.0 - Last modified on 02-03-2025 Revised by David Baniszewski

1.0 - Created on 03-29-2022 Authored by David Baniszewski

The build process on Pantheon is done with Composer, the build prioritizes the composer.json and composer.lock file in the root of the repo, and builds out based on those two files. 

After checking out a site repo from the Pantheon dashboard under the 'connection info' button, composer can be used to to install and uninstall modules via the command line from with the site repo directory, some useful commands are below:

Adding a module

composer drupal/admin_toolbar

Advanced example:

composer --ignore-platform-reqs -W require drupal/admin_toolbar:^3

Removing a module

composer remove drupal/admin_toolbar

Adding libraries via composer

Adding libraries is possible via composer, this allows composer to download and install the library files, freeing you from having to manage them.  Adding libraries to the composer.json is a bit more complicated then adding a module, detailed documentation can be found on the Drupal.org page.

Composer update

Once all needed additions and removals have been done via composer, the update command should be run via:

composer update

This command will run the composer.json file, and build out the composer.lock file, downloading and installing all specific modules and dependencies that are listed as needed for the site.  If you do not wish to install all the files locally, you can run composer update --no-install.  

Commit and push

After installing and/or removing all modules with composer, and running composer update, you are now ready to commit your changes to the site repo and push them back to the Pantheon server to be build.  From your git repo on the command line, or from your git GUI, you should see two files that have been changed, composer.json and composer.lock (if you see other files being changed, please see the pitfalls section below).  Adding your changes with "git add file_name" or "git add ." Commit the changes to composer.json and composer.lock with git commit -m "your message here", and give the commit a message describing what changes were done between the "".  Once you have committed them, you can push your changes to Pantheon with git push.

Once you push your changes, Pantheon will run the composer.json on their servers, and the changes will be deployed to the dev version of your site for review.

Quick version


Potential pitfalls and ways to avoid

The Pantheon build process can balk anywhere it encounters files that it 'expects' to be from Composer being committed in the git repo itself.  Changing and committing files in directories where Composer puts files, especially force commits with git -f force, can cause problems.  It is best to avoid using git -f force as a general rule.

If you have custom code for themes or modules, they should be added to the directories below:

/web/sites/default/modules/custom
/web/sites/default/themes/custom
/web/sites/default/libraries

Pantheon also does not change its build restrictions based on changes to the .gitignore file.  Removing lines from the .gitignore and committing files in those now tracked directories can still lead to the Pantheon build process issues.  We recommand avoiding making changes to the .gitignore file.


Resources:

What is Composer

Using Composer to install Drupal and manage dependencies

Updating a module