Updating an existing Drupal 8 installation to a Composer installation is actually pretty easy. There are already a few scripts out there that will help you achieve this. By following this step to step guide you'll successfully update your Drupal 8 website to use composer.
- Create a new Composer project by executing
composer create-project drupal-composer/drupal-project:8.x-dev my_project --stability dev --no-interaction
- Copy all your custom modules to your_project/web/modules/custom
- Copy all files added on your website. This is usually your_old_project/sites/default/files if you haven't configured a multi-site
- Copy all libraries you are using to your_project/web/libraries
- Now add all contrib modules used in your project to your composer.json by executing
composer require drupal/machinename_contrib_module
- (Optional) Add all other composer compatible libraries you are using (composer require your/library)
- Copy your settings.php file to your_project/web/sites/default
- (Optional) If you are using GIT to manage your code, at this point you can copy all the files and directories in the root folder of your new project to your GIT directory and push the changes to your remote repository
You are now ready to start using Composer in your Drupal project. Happy coding!