Skip to content
This repository has been archived by the owner on Aug 19, 2023. It is now read-only.

Steps to make a non-Composer D7 project work with Drush Launcher #33

Closed
leymannx opened this issue Oct 6, 2017 · 18 comments
Closed

Steps to make a non-Composer D7 project work with Drush Launcher #33

leymannx opened this issue Oct 6, 2017 · 18 comments

Comments

@leymannx
Copy link

leymannx commented Oct 6, 2017

I successfully installed Drupal Launcher and can confirm it works for all my D8 projects built with https://github.com/drupal-composer/drupal-project. Some with Drush 8, some with Drush 9, Drush Launcher always takes the right Drush from /vendor.

Now I do have some old Drupal 7 projects (all of them managed the old way, without Composer) here and would like to restructure them in a way to be able to use the Drush Launcher with them as well.

  • mkdir /User/norman/Sites/my-project
  • cd /User/norman/Sites/my-project
  • composer require drush/drush
  • mv /User/norman/Sites/old-d7-singlesite /User/norman/Sites/my-project/web
  • cd web
  • drush cc all

The Drush launcher could not find a Drupal site to operate on. Please do one of the following:

  • Navigate to any where within your Drupal project and try again.
  • Add --root=/path/to/drupal so Drush knows where your site is located.
  • Add a site alias so Drush knows where your site is located.

Tried all of the suggestions, none of them worked, they all produce the same error message.

What else do I need to do to refurbish an old D7 project and make use of Drupal Launcher there?

@leymannx
Copy link
Author

leymannx commented Oct 6, 2017

Do I need to start over and restructure all old D7 projects along https://github.com/drupal-composer/drupal-project/tree/7.x?

@weitzman
Copy link
Member

weitzman commented Oct 6, 2017 via email

@leymannx
Copy link
Author

leymannx commented Oct 6, 2017

I see, I see. I guess the only other option then would be to skip D7 Composer and make a drush8 command available for the old sites.

@derhasi
Copy link

derhasi commented Mar 28, 2018

As pointed out by @DuaelFr and @webflo in webflo/drupal-finder#35 providing a composer.json skeleton with only drush/drush and a configured installer-path for drupal-core makes the setup work.

{
    "require": {
        "drush/drush": "8.*"
    },
    "extra": {
        "installer-paths": {
            "docroot": ["type:drupal-core"]
        }
    }
}

Edit: You have to composer install after creating composer.json, so drush is installed (in vendor/drush/drush) and recognized by drush-launcher.

@dbjpanda
Copy link

dbjpanda commented Apr 3, 2018

My drupal root is "drupal" and composer.json is

{
    "require": {
        "drush/drush": "8.*"
    },
    "extra": {
        "installer-paths": {
            "drupal": ["type:drupal-core"]
        }
    }
}

But when I am executing drush cc all it says
Command needs a higher bootstrap level to run - you will need to invoke drush from a more functional Drupal environment to run [error]
this command.

@derhasi
Copy link

derhasi commented Apr 3, 2018

@dbjpanda - drush cr is a Drupal 8 command. As this issue is about D7 projects, you may mix up things here. Did you try to run drush status?

@leymannx
Copy link
Author

leymannx commented Apr 4, 2018

@dbjpanda ... and composer install first?

@eigentor
Copy link

The installation with this composer.json file works fine. Everything is ending up in a vendor directory and looks correct. Drush appears to be functional. But: I've tried it on two D7 installation, and I get the "No Drupal site found" Error. Somehow Drush has a problem of recognizing the drupal installation it finds itself in.

This is using DrupalVM, which has Drush launcher installed which works for D8 sites.

@eigentor
Copy link

eigentor commented Apr 10, 2018

So, as I understand this ticket #36 this does not work.
One needs to use Drush Launcher's fallback option.

I went with installing a global drush like described here
https://www.jeffgeerling.com/blog/2018/drupal-vm-48-and-drush-900-some-major-changes
(starting from "Drush Launcher has a convenient fallback option for this. To use it:").

To permanently export
DRUSH_LAUNCHER_FALLBACK=~/.composer/vendor/bin/drush
so you do not have to type before every drush command, create e.g. a
.bash_profile, and write into it
export DRUSH_LAUNCHER_FALLBACK=~/.composer/vendor/bin/drush
This tricked me a little at first, as you actually have to write the "export" at the start.

The fallback option probably should also work with a drush installed locally in your site like described above. But having to do this for every Drupal installation appears more work than to install a global fallback option.

@leymannx
Copy link
Author

leymannx commented Apr 10, 2018

Honestly I don't fully understand what your problem is. But I can absolutely confirm that Drush Launcher works in D7 perfectly fine as long as you have a correctly configured composer.json, see #33 (comment). The following example lives in the D7 root.

{
    "name": "MYPROJECT/MYPROJECT,
    "require": {
        "drush/drush": "~8"
    },
    "extra": {
        "installer-paths": {
            ".": ["type:drupal-core"]
        }
    }
}

@leymannx
Copy link
Author

leymannx commented Apr 10, 2018

I can image this might even work in D6 as well.

@eigentor
Copy link

O.K. I see. As recommended by Moshe one has to use the drupal-composer layout for the drupal project. I did not use that but only the composer.json from #33 (comment).
The solution I describe could still be an alternative if one does not want to install drush seperately for every d7 project.

@i-bajrai
Copy link

You cannot use this strategy to update Drupal core. There is some weird quirk with copying the files that will break everything if you try.

@leymannx
Copy link
Author

leymannx commented Apr 10, 2018

Indeed. Setting the docroot to . breaks update-ability.

~/S/d7 $ drush up -y
Update information last refreshed: Tue, 04/10/2018 - 21:23
Name Installed Version Proposed version Message
Drupal 7.56 7.58 SECURITY UPDATE available

Code updates will be made to drupal core.
WARNING: Updating core will discard any modifications made to Drupal core files, most noteworthy among these are .htaccess and robots.txt. If you have made any modifications to these files, please back them up before updating so that you can re-create your modifications in the updated version of the file.
Note: Updating core can potentially break your site. It is NOT recommended to update production sites without prior testing.

Do you really want to continue? (y/n): y
Unable to load class \Drush\VersionControl\Backup

Whereas putting Drupal into a subfolder works fine:

{
    "name": "MYPROJECT/MYPROJECT,
    "require": {
        "drush/drush": "~8"
    },
    "extra": {
        "installer-paths": {
            "web": ["type:drupal-core"]
        }
    }
}

~/S/d7 $ drush up -y
Update information last refreshed: Tue, 04/10/2018 - 22:45
Name Installed Version Proposed version Message
Drupal 7.56 7.58 SECURITY UPDATE available

Code updates will be made to drupal core.
WARNING: Updating core will discard any modifications made to Drupal core files, most noteworthy among these are .htaccess and robots.txt. If you have made any modifications to these files, please back them up before updating so that you can re-create your modifications in the updated version of the file.
Note: Updating core can potentially break your site. It is NOT recommended to update production sites without prior testing.

Do you really want to continue? (y/n): y
Project drupal was updated successfully. Installed version is now 7.58.
Backups were saved into the directory /Users/leymannx/drush-backups/localhost_d7/20180410204550/drupal. [ok]
No database updates required

@leymannx
Copy link
Author

I guess this only affects updating core.

@weitzman
Copy link
Member

I'll reiterate for clarity

Steps to make a non-Composer D7 project work with Drush Launcher:

This is not supported. If you have a non Composer project, your best bets are to convert to Composer, or use Drush 8 directly, instead of drush-launcher.

@dbjpanda
Copy link

dbjpanda commented Apr 12, 2018

My drupal core is inside var/www/html/drupal So I had set 'drupal'. But unfortunately It didn't work for me.

"installer-paths": {
            "drupal": ["type:drupal-core"]
        } 

But when I set 'core' instead of 'drupal' It works :)

"extra": {
        "installer-paths": {
            "core": ["type:drupal-core"]
        }
    }

Incase any one wants to set up a D7 with all the tools available in one click he/she may have looked at this https://github.com/dbjpanda/digitalocean-drupal/tree/7.x

@leymannx
Copy link
Author

leymannx commented Apr 12, 2018

@dbjpanda When you start a new D7 project you'd better start it with https://github.com/drupal-composer/drupal-project/tree/7.x instead of just the Composer skeleton from this thread.

composer create-project drupal-composer/drupal-project:7.x-dev some-dir --stability dev --no-interaction

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants