0

The http://docs.drush.org/en/master/install page states:

Drush 9 only supports one install method. It requires that your Drupal 8 site be built with Composer and Drush be listed as a dependency.

and if you go to https://github.com/drupal-composer/drupal-project and follow the given steps, in particular run the composer create-project drupal-composer/drupal-project:8.x-dev some-dir --stability dev --no-interaction command, then:

  1. You will have to create an empty directory (otherwise it will complain the given directory is not empty);

  2. It will create Composer structure with Drupal 8 located in web sub-directory;

  3. It will also create vendor sub-directory with lot's of other sub-directories as:

    alchemy composer doctrine fabpot league phar-io sebastian theseer asm89 consolidation drupal grasmash masterminds phpdocumentor squizlabs twig autoload.php container-interop drupal-composer guzzlehttp mikey179 phpspec stack vlucas behat cweagans drush instaclick myclabs phpunit stecman webflo bin dflydev easyrdf jakub-onderka nikic psr symfony webmozart chi-teck dnoegel egulias jcalderonzumba paragonie psy symfony-cmf zendframework

Now with regard the new way of isntalling Drupal 8 I have two questions:

  1. Previously we would install Drupal 8 in document root set by control panel. Different control panel have different document roots, ours default them in /home/username/public_html.

Now, with the new way of installing Drupal 8 we end up with document root located in /home/username/some-dir/web, which does not play nice with our control panel's defaults. So I wonder what is the best recommended practice here?

Creating symbolic links between the old and new document roots also have its issues. For example, if you switch to /home/username/public_html (which is a symbolic link to /home/username/some-dir/web) and run the composer update command then it will give:

No composer.json in current directory, do you want to use the one at /home/username/some-dir? [Y,n]? 

and we would really like to avoid this kind of extra steps, but at the same time respecting our control panel's default settings.

Changing the default setting for document roots in control panel is also not a good option as there could be lot's of old and non-Drupal websites on servers, so the old document root must be kept.

  1. Do we have to have Composer structure with lot's of sub-directories like ones in vendor in every website's home directory? Please note that in my test setup Composer is installed globally. But when you run the composer create-project drupal-composer/drupal-project:8.x-dev some-dir --stability dev --no-interaction command it creates all those directories within a website's home directory.
3

You do not necessarily have to run composer create-project drupal-composer/drupal-project:8.x-dev some-dir --stability dev --no-interaction to create a new Drupal 8 site using the drupal-project composer package.

You can also just download the composer.json of that project and place it into your future Drupal 8 base folder. Then you can alter the installer paths within that composer.json to your liking. So if you prefer public over web as your Drupal root, then rename that part of the installer paths. You may also wish to alter the project name or other details of the composer.json file.

After your customization, you can then run composer update to generate an according composer.lock file. Assuming you did so on a local development environment, you can then use composer install --no-dev on your production system after uploading your composer and custom files/checking them out if you use a code versioning system.

Coming to the folder structure: It is advisable to keep the folder above the Drupal 8 root as base folder of your root package (project), location for the composer dependencies (vendor folder), Drush site settings, and auxillary files that should not be directly accessible from your web URLs (e.g. exported configuration files, private files, temporary files, Node.js packages, ...).

Therefore you should consider pointing your virtual hosts' root directories for example to /home/username/public_html/web (or /home/username/public_html/public, if you customized your composer.json like that) while using the regular root directories of your hosting panel /home/username/public_html as composer root package folder.

Depending on your hosting panel, you may have the ability to alter the vhost root directory by overriding the web server settings (e.g. defining a DocumentRoot for Apache, or a root for Nginx). How to do this depends heavily on your used hosting solution and is therefore off-topic in Drupal Answers.

And yes, you will have this folder structure on every of your projects. As every project may require a different version of dependencies, different modules (which may add dependencies with certain version restrictions to the vendor folder as well), binary tools for the shell, probably applied patches and so on. These dependencies and their version requirements are project specific, even when you use a global Composer installation.

  • Mario, thanks for the detailed explanation. Before accepting your answer, mind elaborating little further? As sated in 1) running Composer in /home/username/public_html, it complains the directory is not empty. And that directory unfortunately can not be empty, because the control panel places bunch of own files and directories in it. Thus the problem. So would you advice create Composer in empty directory first and then move the whole structure back to /home/username/public_html to mix everything up? Changing document root and Apache configuration is not an option for. – Nick Mar 23 '18 at 11:16
  • As stated within my answer: Use Composer within public_html, not one folder above. Empty it, if required. This leaves you with a Drupal root in a subfolder of public_html. Then alter your vhost document root to point to that subfolder. I'm pretty sure you can do so, as all (good) hosting solutions allow for additional server directives. Benefit of this solution: public_html may have been added to the PHP open_basedir already by the hosting solution. So you don't need additional settings to access private files outside your Drupal root. – Mario Steinitz Mar 23 '18 at 11:48
  • I know I could alter doc root, but I really wanted to keep one standard document root for all types of other websites and CMS like WordPress across the server, because the control panel has bunch of automated scripts bound to that kind of default structure. Is there any other way of not changing document root? – Nick Mar 23 '18 at 12:01
  • According to your folder structure description: I doubt it. Maybe you're able to create a dedicated vhost template for Drupal 8/Magento 2/... that all use a similar project structure and built-in composer dependencies. Or you will end up mixing project code with server stats and so on, which makes it pretty unhandy for using code versioning or automatic deployments. But that really is off-topic in Drupal Answers... – Mario Steinitz Mar 23 '18 at 12:09
  • Fair enough. I accepted your answer as it provided more details. Thanks a lot! – Nick Mar 23 '18 at 12:22
0

with the new way of installing Drupal 8 we end up with document root located in /home/username/some-dir/web, which does not play nice with our control panel's defaults. So I wonder what is the best recommended practice here?

Navigate to the directory, then run the composer command. Composer will install Drupal at the directory from which you run the command.

Do we have to have Composer structure with lot's of sub-directories like ones in vendor in every website's home directory?

Each Drupal 8 (and likely 9+) will have its own /vendor directory.

  • When I run Composer in /home/username/public_html, it complains the directory is not empty. And that directory unfortunately can not be empty, because the control panel places bunch of own files and directories in it. Thus the problem. – Nick Mar 23 '18 at 11:09
  • Delete all those files. You don’t need them. – Jaypan Mar 23 '18 at 11:10
  • Believe me I do. Those are: awstats cgi-bin domains etc fcgi-bin logs mailboxes Maildir private public_html tmp www. – Nick Mar 23 '18 at 11:27
  • And sorry for confusion, I tried to run Composer command in /home/username and not in /home/username/public_html as previously stated, because /home/username/public_html is the root where Drupal 8 should reside, however one level up there are bunch of NEEDED files and directories. – Nick Mar 23 '18 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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