Score:2

Is there any problem with installing composer globally?

us flag

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?

Jaypan avatar
de flag
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: https://www.morpht.com/blog/drupal-and-composer-part-1-understanding-composer
Jay Williams avatar
us flag
@Jaypan Thank you reading your posts now.
4uk4 avatar
cn flag
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 avatar
cn flag
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.
Score:3
nr flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.