This is my approach to converting a Drupal (version 8.8 or greater) site from being built with tarballs and the GUI to a Composer-based site. I use ddev for my local environment to set up containers that provide Docker, Composer, and Drush. This approach assumes some degree of comfort with the command line interface (CLI).
 
  • Inventory the source site for contrib modules and themes and make a list of modules and themes with versions. I use a spreadsheet for this.
    • Find modules and themes in the hierarchical directory tree in your code base.
    • Find versions by looking at the list of modules or themes in Admin panel. 
    • Get machine names and versions in Admin panel on  modules list and themes list on Appearance page.
    • It can be very helpful to install the upgrade status module, which will generate a report that lists your currently installed modules, their version number, and available upgrades.
    • (Do the same with custom modules and themes if you have any.)
  • Prepare specific materials from source site for later import:
    • Create a folder for composerize info
    • Make and download a tar.gz or zip of the files (cd to web/sites/default , then tar -zcvf files.tar.gz files)
    • Export a copy of the database (either BUM or phpMyAdmin)
    • Download a copy of settings.php and then name it old<site>settings.php
  • Create a new ddev Drupal project with defined directory structure using recommended-project template:
    • cd Sites
    • mkdir <project-name>
    • cd <project-name>
    • ddev config --project-type=drupal8  --docroot=web  --create-docroot  --mariadb-version="" --mysql-version="8.0"
  • Now you have an appropriate directory tree in: /Sites/project-name
    • (Until DreamHost updates their mysql from 5.7 to 8.0) create in .ddev a mysql directory and add a collation.cnf file: .ddev/mysql/collation.cnf
    • [mysqld]
    • collation-server = utf8mb4_unicode_ci
    • character-set-server = utf8mb4
  • Start the ddev container:
    • ddev start
    • Now you have the configured container running with ddev tools, and web access urls created (but not yet usable)
  • Install Drupal core using composer
    • ddev composer create  "drupal/recommended-project:8.9.2" (use the correct 3 digit version to get the correct drupal core.
    • You will use the existing core modules and themes and deal with updating core later...)
    • It knows which version because you have configured the container.
    • It will ask about overwriting /web - Yes
  • Make sure drush is available:
    • ddev composer require "drush/drush"
  • Create directories in project root
    • private
    • private/BUM
    • tmp
    • config/sync
  • Fix new settings.php by transferring settings from source settings.php into new project settings.php:
    • $databases['default']['default']
    • $settings['hash_salt']
    • $settings['trusted_host_patterns'] (if this has been set)
    • Set path to private: $settings['file_private_path'] = $app_root . '/../private';
    • Set path to tmp: $settings[$settings['file_temp_path'] =] = $app_root . '/../tmp';
    • Set path to config/sync: $settings['config_sync_directory'] = $app_root . '/../config/sync';
  • Add contributed modules:
    • (Manual method: edit json file - not recommended)
    • Composer method (recommended):  run ddev composer require "drupal/<module-name>:<version>"
    • Can do as one command: ddev composer require drupal/module-name-1 drupal/module-name-2 drupal/module-name-3  etc
    • Use quotes
    • About versions:
      • Find composer require string by clicking version number on module page of drupal.org
      • If we do not specify a version, we will get the latest version, which could be a problem, so best to specify a version.
      • ^1.0 = latest stable version at 1 or greater (generally best option to pick)
      • ~1.0.0 = anything below 1.1 (~ allows only last number to increase when doing semantic numbering)
      • ^1.0.0  = anything after first number that gives major version can increase, so up to 1.0.99 but NOT 2.0
      • 1.x-dev = always dev
      • 1.1.4 = exact version
      • Ranges can also be specified as ">" (greater than), ">=" (greater than or equal to), "<" (less than), or "<=" (less than or equal to).
    • Finalize this: ddev composer install
  • Add contributed themes:
    • (Manual method: edit json file - not recommended)
    • Composer method (recommended):  run ddev composer require "drupal/<theme-name>:<version>"
    • Find composer require string by clicking on version number on Drupal.org
    • Use quotes
    • Can do as one command (see modules) or one at a time
    • Finalize this: ddev composer install
  • Add files with user-generated content (/web/sites/default/files)
    • Add ALL files but do not replace  - ore remove - the generated files: js, php, css
  • Import database
    • Put exported SQL file in root of project-name
    • cd Sites/project-name
    • (ddev import-db source=dbname.sql did not work)
    • ddev import-db  and then giving full path when prompted worked: /Users/pheski/Sites/project-name/file.sql
  • Use drush to update db and clear cache
    • ddev drush updb
    • ddev drush cr
  • Launch site
    • ddev launch
  • Now make modifications in order to upgrade core to current version (9.3.x)
    • Install and set as default a D9 compatible theme
    • Update modules
    • Update core
 
After testing and making changes/improvements it gets moved to production:
  • Export db (file.sql)
  • Create zip or tar.gz of entire project
  • Upload  db file to level above production root
  • Upload and uncompress zip or tar.gz of entire project (note: drupal codebase is in project-name/web directory!
  • Export a copy of the production db 'in case'
  • Use SSH to import the new db into the production db (you DID make a backup, right?)
  • Using the DreamHost panel, redirect the server to project-name/web
  • Remove the TLDN from the old version...
  • (Note - can do this with a new production db and new project, removing the tldn from the old project so it is easy to revert.)
Code_topic