2

I have a VPS and will be hosting a mixture of drupal 8 and drupal 9 sites. I need to install composer to manage the sites.

Is there any need to install composer in a project folder or can I just install globally?

4
  • 2
    You can install it globally. I don't even think you can install it per project, as it's used to manage your project. Here's a series of blog posts I wrote on using Composer with Drupal: morpht.com/blog/…
    – Jaypan
    Oct 3, 2021 at 20:11
  • @Jaypan Thank you reading your posts now. Oct 3, 2021 at 20:13
  • Globally/locally has very different meanings depending on the context. In case of composer it is about how to download and run an executable in a specific OS. If you have full control over the server you probably want to download it to /usr/local/bin/composer. If not you need to find a place within your user directory or web space wherever you have the file permissions to do so.
    – 4uk4
    Oct 3, 2021 at 20:57
  • Using composer is a completely different topic. By default composer installs everything locally. The option to install globally was added at the beginning for convenience. It is against the idea of composer and now considered as deprecated. Drupal doesn't use it.
    – 4uk4
    Oct 5, 2021 at 8:15

1 Answer 1

3

There is no problem with installing Composer globally, but there may be a problem with using composer global require to install individual Composer-managed projects globally.

You should not run in to this trouble just using Composer on the server to composer install your various Drupal 8 and Drupal 9 sites, but you should be aware of the potential for dependency conflicts, especially in local development environments.

To avoid this, use consolidation/cgr instead of composer global require:

$ composer global require consolidation/cgr

After globally requiring that one package, you can use cgr as a drop-in replacement for composer global require and it will prevent dependency conflicts with globally-installed packages. For example, to install Drush globally:

$ cgr drush/drush

Note that current best practices now say to install a site-local Drush by adding Drush as a dependency of your Composer-managed Drupal project; I just used this as an example of how to use cgr.

By the way, if you are still running Drupal 8 sites, please be aware that Drupal 8 reaches its end of life on November 1, 2021. Here are some tips on upgrading Drupal 8 to Drupal 9.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.