Drupal-project: How to install drupal to root directory, not /web?

Created on 27 Mar 2017  路  7Comments  路  Source: drupal-composer/drupal-project

Hi,

My site root directory is: /var/www/mysite.com

I installed composer via composer create-project drupal-composer/drupal-project:8.x-dev /var/www/mysite.com --stability dev --no-interaction

Everything works fine except that now my site address become mydomain.com/web/core/index.php instead of mydomain.com/index.php.

Any way to fix that?

Thanks

support

Most helpful comment

Could this be added as a piece of configuration? This would allow people to use this composer project without having to adopt the project's opinionated file structure.

For example, we are already putting our files in /web/public and not just /web if this directory structure where a part of configuration then we could use this project without forking/modifying all the places where this directory is used.

All 7 comments

Add --no-install to the composer create-project. Adjust the paths in composer.json and run composer install. But its this setup is not recommended because this the vendor folder will end up in a web accessible path. It is more secure to change the webserver config to work with the default folder layout.

Could this be added as a piece of configuration? This would allow people to use this composer project without having to adopt the project's opinionated file structure.

For example, we are already putting our files in /web/public and not just /web if this directory structure where a part of configuration then we could use this project without forking/modifying all the places where this directory is used.

Changing the composer.json is easy. But .gitignore and a few other files is not so easy.

If it can be changed in one place it would be a non-issue. As it is, it is in 5 places just in the composer.json

I am also not sure if the drush policy will still be enforced with a different folder structure.

Replying to old questions but hopefully it helps someone in the future. Also, I believe this issue can be closed because there are simple fixes to both questions.

@superfedya It is now best practice to have certain files outside of the root public directory. This is why many frameworks and CMS have a "web" or "public" or "pub" directory where the public files can live. A directory below that is where sensitive things like .git, private files and such can live.

The simple way to deal with a /var/www/mysite.com/web is to edit your web server's document root. For example, in Apache this would mean setting DocumentRoot /var/www/mysite.com/web This should be easy even if you don't have access to your Apache or Nginx configuration files because changing the document root is a basic setting in shared hosting platforms like cPanel and Plesk.

@frob the drupal-project allows you to specify different install paths if you don't like /web. You simple edit the extra.installers-paths section of the main composer.json. For example, if you prefer /web/public instead of /web then it would look like below

    "extra": {
        "installer-paths": {
            "web/public/core": ["type:drupal-core"],
            "web/public/libraries/{$name}": ["type:drupal-library"],
            "web/public/modules/contrib/{$name}": ["type:drupal-module"],
            "web/public/profiles/contrib/{$name}": ["type:drupal-profile"],
            "web/public/themes/contrib/{$name}": ["type:drupal-theme"],
            "drush/contrib/{$name}": ["type:drupal-drush"]
        }
    }

Also the drupal-launcher uses that installer-paths entry to find drupal root so it would be compatible with the above approach.

Was this page helpful?
0 / 5 - 0 ratings