Effortless Drupal Reinstallations: A Quick Guide Using Composer

Image
The picture shows a dark linux terminal with the reinstall command mentioned in the blog post

Reinstalling a Drupal project is a routine task for developers. Whether you're testing new features or ensuring smooth installations on different setups, it's a critical part of the process. In this blog post, I'll show you a swift and straightforward method using a composer script.

The Need for Reinstallation

Reinstalling the project you're working on is a task you might find yourself doing multiple times a day, depending on the tasks at hand. Whether you're testing a feature your colleague has been working on or ensuring that your feature installs correctly on different setups, a reinstall is often necessary. One common method is importing a database from a backup. However, this isn't always feasible due to large database sizes or limited access to a backup.

The Composer Script

Drupal is capable of creating a new site from existing configurations, and we can leverage this feature. You can add the following snippet to your composer.json:

"scripts": {
   "project:reinstall": [
       "[ ! -z $(drush core:status --field=db-status) ] && drush cache:rebuild || true",
       "drush site:install minimal -v --existing-config --account-name=admin --account-pass=pass --account-mail=\"[email protected]\" --yes",
       "drush cache:rebuild",
       "drush user:login"
   ]
}

Be sure to adjust the parameters to meet your specific needs.

You can call this script then with: 

composer project:reinstall

After running this script, you'll have a clean installation with your current exported configuration. If you require content for further testing, you can use drush devel or a migration with demo content. I'll delve deeper into this in an upcoming blog post, scheduled for release in a few days.

Conclusion

Now, you're equipped with a simple and efficient way to reinstall your Drupal project using Composer. It's a valuable skill for any developer, ensuring that your changes will install correctly on various installations. Stay tuned for my next blog post, where I'll explore how to add content for thorough testing. Give it a try, and feel free to share your experiences or questions in the comments.

Comments

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.