6

I want Drush 9 on a Drupal 8 production server without having to install Composer. Is there any way to do this?

And if that is not possible, can anyone suggest an alternative to Drush especially for maintenance, updating and syncing the site with dev and staging?

4
  • Why not install composer? You can install composer in a project independent way, e.g. inside a drush-specific directory, and that would allow you to not only have drush 9 but also run future updates on it without workarounds. Commented May 7, 2018 at 8:18
  • 1
    To be blunt, and ignoring other issues, composer is a ridiculous resource hog. I have some very small D8 sites I want to put on a server or two and be able to ssh in and run the odd drush command. I do not need, nor do I want, the overhead of composer. As the servers and sites are small I am likely to have issues even using composer without running out of memory. I will have very few dependencies to worry about and I am the only person working on the site.
    – tanbog
    Commented May 7, 2018 at 11:56
  • Just as a side not, yes composer can be a hog when doing dependency resolution and picking a set of compatible versions. If you have a lockfile, though, and just do a composer install, the overhead is a lot smaller since it just installs what is in the lockfile.
    – mpdonadio
    Commented May 7, 2018 at 14:27
  • 1
    Not to mention that if you're looking for a way to break your environment, Composer is perfect way to ruin your day. One little mistake, and your environment becomes smoking rubble
    – sea26.2
    Commented Nov 10, 2018 at 22:09

3 Answers 3

11

If you don't want composer in production on your server, you can run the composer commands locally to install Drush, then make sure to push the vendordirectory to the server. Make sure to also commit the composer.json and composer.lock files, so that anyone else working with the codebase can handle composer on their own local machines as well.

In this way you never need composer on the remote production server, but can get drush.

9
  • 1
    If I push the vendor directory. Do I need to take further steps to then use drush on the server? So, for example, I have several sites on the server and want to use Drush to manage them globally via aliases. I am guessing this wont work out of the box with only a vendor directory for each site?
    – tanbog
    Commented May 7, 2018 at 7:58
  • 1
    Ideally you should install Drush Launcher (docs.drush.org/en/master/install), but that said, Drush will exist at vender/drush/drush/drush, so you can use it without Drush Launcher if there is some reason why you are not able to install that.
    – Jaypan
    Commented May 7, 2018 at 8:01
  • 1
    Is there any point to everything else in the vendor folder then? Shouldn't I delete or gitignore the rest of that folder since there will be no composer on the server?
    – tanbog
    Commented May 7, 2018 at 12:11
  • 2
    Anything in your vendor file will be required. If you aren't using Composer on your server, you need to be doing it locally, and then pushing to the server. The files in the vendor folder will be required.
    – Jaypan
    Commented May 7, 2018 at 12:28
  • 2
    The vendor directory is set to be ignored in the .gitignore file. It sounds like you need to fix that.
    – Jaypan
    Commented May 11, 2018 at 5:47
2

On the production stage we don't need Composer (neither composer.json nor composer.lock), Composer is used to build your project and to generate the vendors after that it is necessary to pack all the generated files and to deploy them on the target server.

4
  • 1
    How do I get Drush on the production server without composer being present? Sorry if this seems like a silly question but the composer and drush guides out there are super confusing on this.
    – tanbog
    Commented May 7, 2018 at 7:56
  • Drush is present in your vendors directory that will be deployed in your server, so all you have to do is settings the path to drush /vendors/drush/drush. Commented May 7, 2018 at 13:10
  • 1
    how exactly do you "pack" the vendors folder?
    – tanbog
    Commented May 7, 2018 at 13:30
  • You can use maven or phing to package your web site and then put it in the server. Commented May 18, 2018 at 11:54
1

If you build out your D8 site locally in your dev environment using Composer, you'll have Drush 9. Then, if you commit your D8 instance (Git) and pull onto your server, you'll have Drush- albeit you'll have to execute using the full path. For example: From my command line on a Ubuntu 18.04, I can execute

$ vendor/bin/drush pml --no-core

My D8 instance on the Production servers contains the following at the root.

enter image description here

Notice that /vendor is committed and present in this repository. And that contains /vendor/bin/drush

Refer to the Drush Documentation for more info.

Hope this helps!

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.