Hi 

I have installed Drupal 8 using Composer and everything is fine.

When you install with Composer your Drupal 8 is installed in a web directory in your public_html directory.

For example: public_html/directory_name/web

This gives you a URL for your Drupal 8 site of:

http://your_chosen_name.co.uk/directory_name/web/

What I want is my URL to not have the directory_name/web/ on the end of it. I just want it to be:

http://your_chosen_name.co.uk

How do I do this? There have been a couple of posts about this but surprisingly no clear answer.

I would have thought that if many installations of Drupal 8 using Composer created this issue there must be a simple answer.

Many thanks for any replies

Comments

VM’s picture

if you can't adjust composer's installation directory via its configuration, then you can adjust the document root on your server to have the host name resolve to the subdirectory. I'd dig in with composer first though.

edit: see https://github.com/drupal-composer/drupal-project/issues/258

donm’s picture

In a Composer-driven workflow, using the recommended drupal-composer/drupal-project for one's install, I've found it useful to distinguish these 3 different locations:

  1. Project root directory: this is where your top-level composer.json file lives. (For non-developers like me using Composer, I treat it as a fetch program, with the .json file being the list of what to fetch and where to fetch from. If you Google on how to use WordPress [can I say that here?] with Composer, there are some useful "how to" articles that are transferable to using Drupal.)
    1. In general, one invokes Composer from this directory.
    2. This is the directory where Composer will write the /vendor folder, with the various dependencies needed for the project in question.
    3. In my shared hosting account, I do have access to this directory (with owner:group permissions for my user). But I've not tried to run Composer in that environment.
  2. Drupal root directory: identified by being where Drupal's top level files live; in particular, update.php. In the stated project, this will be one level down from the project root directory.
    1. In Drupal 8, one will find a few items (such as private files path, and the /config/sync folder settings, and the location of the /tmp folder, and maybe even the location for backup files using the Backup & Migrate module) that talk (obscurely) about pointing the location of those folders to a place outside the next location (the publicly accessible folder). So in my cloud server environment, where I have shell access, and control over setting ownership and permissions, I point those locations to the project root folder (from Drupal's folder: ../tmp, for example).
  3. One's desired publicly-accessible directory; in Apache settings called "docroot"; in your question, the "public_html" directory. This location is governed by a) the general settings for your web server; b) plus any virtual hosts set up; and c) as modified (if things are set up that way) by any .htaccess file (ie, this directory is governed by webserver settings, and has nothing to do with Composer or Drupal, except as the underlying environment).
    1. In the particular project that creates the /web directory [which is the Drupal top level], I find it simplest to point my virtual host at that /web directory [ie, treating this /web directory as the /public_html directory in your set-up].
    2. In theory, it is possible to adjust one's Composer project to direct the Drupal portion of the install to a directory of one's choice. I'm not talking about the top level project root; I mean adjusting the /web directory location within that project; in your example, replacing /web with /public_html. I tried doing so once; but there are a lot of moving parts to that particular project, and I couldn't chase down all of the places where I needed to make that change. I've learned to accept that particular part of the world as it is.

So, in your situation, there are two broad options:

  1. If a) you have access to the folder above /public_html (ie, what I'm calling the project root), and b) either yourself or with your hosting provider can adjust the web server environment, do a re-install by invoking Composer in that project root. And then try either:
    1. adjust the virtual host settings to point the webserver environment from /public_html to /web, or
    2. to copy everything from /web to /public_html. Though note that with this latter option, you'll need to edit the composer.json file to replace /web with /public_html [in the portion of that file that tells Composer where to install things].
    3. With a third possibility, which I've only read about and never tried, as it's more advanced Linux config magic, being to set up symbolic links from the /web directory to the /public_html directory, and seeing if the server will recognize that setup.
  2. If you are stuck invoking Composer from the /public_html folder, then you will have to use one or more of the following options. All of which are part of much older discussions about how to serve Drupal from a subfolder; just search here at Drupal.org.
    1. Here, for example: https://www.drupal.org/forum/support/post-installation/2015-10-15/solved...
    2. In my shared hosting environment (where I have almost no control), with my Drupal install being one folder below the /public_html folder, my solution was to write a suitable .htaccess file to point to the Drupal subfolder. [In your situation, this would be a new .htaccess placed in your /public_html folder that then points the web server to the /web folder.]
      1. Apache documentation says that configuration set thru .htaccess files is slower than set thru virtual host settings.
    3. Depending on the contents of one's project level .htaccess, it may or may not be necessary to set one or both of the a) "RewriteBase" directive (located in the .htaccess file in the Drupal top level), and/or b) the "$base_url" item in settings.php. Compare with the 2015 article linked to above.
    4. Here is the relevant portion of my .htaccess file, which is located in my /public_html folder [which I got from someone's website in 2014, which has since disappeared; compare to the relevant portion of Drupal's .htaccess file]. It's for a D7 install, with the D7 top level being in /drupal7 (ie, /public_html/drupal7). I'm not a webserver expert, so don't fully understand what each line is doing. (You can research the directives at Apache docs.)
      1. Note that lines 2 and 3 and probably 4 below are a re-write rule to serve requests from https:// and not from http:// -- which only applies if you have an SSL certificate installed for your website. Use the pound sign (#) to comment out any line not relevant to your situation.]
      2. In my situation, I don't have to activate RewriteBase / in Drupal's .htaccess file [perhaps because it's there in line 1; but I haven't experimented], but I do activate the setting for: "$base_url = 'https://www.example.com';" in settings.php. But your mileage may vary.
      3. And in your situation as stated in your question, remember that you might have to point things two levels down (from your /public_html folder). My D7 subfolder is only one level down from /public_html. Your situation is: /public_html/[Composer top level]/[web -- ie, Drupal top level]
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule .* https://www.example.com/ [L,R=301]
RewriteRule ^$ drupal7/index.php [L]
RewriteCond %{DOCUMENT_ROOT}/drupal7%{REQUEST_URI} -f
RewriteRule .* drupal7/$0 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* drupal7/index.php?q=$0 [QSA]
mmjvb’s picture

You domain needs to specify the correct DocumentRoot: ....../web.
Note: that should be the absolute path in the filesystem up to and including the web folder.

Looks like it currently points to the folder that directory_name resides in.

besto’s picture

Hi, can you help me to set the root folder as am stuck from last week to fix the root folder. if we have cPanel details is it easy to setup the root folder to add /web or any other control needed?.. currently site running with /web? 

mmjvb’s picture

Just make sure it ends in .../web. 

besto’s picture

Thank you for replying.. if I share cpanel details will you be able to check. 

rwilson0429’s picture

Pretty simple to fix. As mmjvb state, just change your document root to point to the /web folder.  In this particular case in this issue, it would be 'public_html/directory_name/web'.

ReggieW

fkelly12054@gmail.com’s picture

or see:

https://www.drupal.org/docs/develop/using-composer/using-composer-to-man...

which explains how to use the no-install option with composer so that you can put the files where you want. 

mmjvb’s picture

These projects are setup a certain way, advice against changing that. No problem to rename web with docroot or whatever you like as alternative.
But removing the folder or placing the folder outside the original project is not something I would recommend.

With the domain pointing DocumentRoot to public_html you would need the content of web to be placed in public_html. Wouldn't recommend that nowadays. When putting web content into public_html/directory_name you would need some htaccess rules to remove directory_name from the url. Wouldn't recommend that either. See no problem with setting DocumentRoot properly. 

calefilm’s picture

I am so lost on this topic.  I even have a dedicated server and direct access to the inner workings and cannot find a solution.  The server techs i'm speaking to (not experienced with drupal) say i can't change the Document Root (only on subdomains)... one even suggested creating another main domain and making my current domain a subdomain... argh!  In my example, i want users to navigate to mysite.com, not mysite.com/web.

I appreciate the posts above but they sort of go over my head.  I can understand it a little but it's obvious there is no clear solution.... Is there today in April 2019?

The Drupal root files are located in 'web' inside public_html/web/  

Still not understanding if it's possible... i'd like the drupal files to load from public_html/web/ at mysite.com .... not mysite.com/web

I don't plan on moving or changing my 'web' directory from public_html/web

Is there one answer and can you detail the solution and explain in laymen terms for idiots like me to achieve this?

Thank you! 

calefilm’s picture

I'll respond to my own self as it may be helpful for others going through the same thing.  

I talked to another tech and she was very helpful.  'Document Root' was in her vocabulary and helped me by editing /var/cpanel/userdata/cpanel_name/domain.com

documentroot: /home/cpanel_name/public_html/web

I didn't like the idea of messing with composer.json files and installing drupal files anywhere else but inside public_html.  I prefer only making changes on the server side. In this case i needed access to, or i needed an expert to access my server directories to reconfigure document root.

Greenman77’s picture

Calefirlm,

I hardly ever comment but thought this might be the time was given I've also wasted too much time on this problem and have a similar setup from the sounds of it. I find that the solution you proposed although it is the simplest and definitely preferred may have some potential to be overridden back to public_html when an account is modified or some other action has occurred on the cpanel account. I found this out the hard way.

I also wanted to avoid a composer modification and some other solutions such as this one from intrafusion which seemed like it worked perfectly except when I wanted to redirect from a non-www to a www address (with https) a /web was added and a "page not found" error displayed.

What has works for me

In public_html/.htaccess

 RewriteBase /
 RewriteCond %{HTTP_HOST} !^www\.sitename\.com\.au$ [NC]
 RewriteRule .* https://www.sitename.com.au/$1 [L,R=301]

  RewriteRule ^$ web/$1 [L]
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ web/$1 [L]

In /web/.htaccess

no changes

settings.php

if (isset($GLOBALS['request']) && '/web/index.php' === $GLOBALS['request']->server->get('SCRIPT_NAME')) {
  $GLOBALS['request']->server->set('SCRIPT_NAME', '/index.php');
}
calefilm’s picture

Thank you for your detailed response! I'm going to try this out.  I've now changed my document root back to:

/home/cpanel_name/public_html

Now, let's say I installed my project into 'abc' directory, so my file manager looks like this:

/home/cpanel_name/public_html/abc/web

i'm wondering if I can get away with doing this?  Because I would like to organize my public_html directory, so each project has its own folder.  So let's say my domain is abcsite.com, located at /home/cpanel_name/public_html/abc/web.... can i set up my .htaccess file so that a user can navigate to abcsite.com? 

I'm going to try and edit the .htaccess file inside my /abc project name, as instructed, and leave the .htaccess file alone at /abc/web, as instructed, and see what happens.

Caro77’s picture

Hi, 

Greenman77, it worked for me.

Thank you!

abstractmchatham’s picture

This method was working great, however it appears to break the Calendar module on a site that I tried this on. Would you have any insight on how to avoid this?

Greenman77’s picture

@abstractmchatham I'm not sure the break is related to the basepath configuration I've suggested. I've also installed the calendar module just to test this out. I was able to create a content type with event date field with a calendar pretty quick and easily and it still seems to function ok using the same basepath configuration. Perhaps there's some other difference in versions or configuration. Best to be a bit more specific about how it breaks and any errors that are generated. 

abstractmchatham’s picture

I believe you are right, I get this error: Drupal\Component\Plugin\Exception\PluginNotFoundException</em>: The "calendar" plugin does not exist. in <em class="placeholder">Drupal\Core\Plugin\DefaultPluginManager-&gt;doGetDefinition() when viewing the page or trying to clear the cache. Also this is logged: Undefined index: calendar in Drupal\views\Views::pluginList()

I'm not very familiar with drupal, and less with composer. I was simply tasked with migrating the install to a cpanel account. It is Version 8.6.2

aangel’s picture

This is what I did to rearrange my local installation to use public_html:

"extra": {
    "composer-exit-on-patch-failure": true,
    "patchLevel": {
        "drupal/core": "-p2"
    },
    "installer-paths": {
        "public_html/core": ["type:drupal-core"],
        "public_html/libraries/{$name}": ["type:drupal-library"],
        "public_html/modules/contrib/{$name}": ["type:drupal-module"],
        "public_html/profiles/contrib/{$name}": ["type:drupal-profile"],
        "public_html/themes/contrib/{$name}": ["type:drupal-theme"],
        "drush/Commands/{$name}": ["type:drupal-drush"]
    },
    "drupal-scaffold": {
        "initial": {
            ".editorconfig": "../.editorconfig",
            ".gitattributes": "../.gitattributes"
        }
    }
}
meeks53113’s picture

Hi, if this isn't related please let me know.  Basically, I'm trying to download the OAuth  module using Composer to my Drupal root directory.  My Root Directory.  How do I connect Composer to my Drupal root directory?  I'm with GoDaddy.

Composer is working. I have the correct PHP file (Windows) so Composer is working.  I type: 

composer require "drupal/social_api:2.x-dev" "drupal/social_auth:2.x-dev" "drupal/social_auth_google:2.x-dev"

I get..

  [InvalidArgumentException]
  Could not find a matching version of package drupal/social_api. Check the package spelling, your version constraint
   and that the package is available in a stability which matches your minimum-stability (stable).

require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-suggest] [--no-update] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--update-with-all-dependencies] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--] [<packages>]...

can someone help?

meeks53113’s picture

also, here's where I need the file..

/public_html/core/modules

mmjvb’s picture

Sounds like the drupal 8 modules are not made available. By default only what is available on packagist can be used. To use the modules of drupal you need to specify the repository in your project:
`composer config repositories.drupal composer https://packages.drupal.org/8`

Not having that repository mentioned means the code base of your project is not ready to be managed with composer. How did you start with this project? Are you sure you are in the root of the project when running the composer command?

Can you provide the output of `composer show -s` ?

As far as the destination is concerned, composer defaults to the folder vendor in your project. The destination is rather static, it can be changed, but that doesn't move what you already have. You need to make sure everything is where you specified. With drupal projects it requires a plugin composer/installers in order to set destination for specific packages. You need to configure extra/installer_paths by setting the destination for specific packages or package types. Normally, a distribution has this configuration in place. You would still need to check it, though.

meeks53113’s picture

ok mmjvb, not really related.. lol. thats tough. here's the output of 'composer show -s'..

C:\Users\002>composer show -s
name     : __root__
descrip. :
keywords :
versions : * No version set (parsed as 1.0.0)
type     : library
source   : []
dist     : []
path     :
names    : __root__

mmjvb’s picture

Rather empty. You either haven't created the project with composer or are not in the project root. 

meeks53113’s picture

i see, i see.. 'composer show -s really provided some insight. is the repository where im getting the module from? if so, how would i ask composer to access drupal?  i mean, typically, i search on drupal for the module i want select the file, download it to my desktop, then drag folder to /public_html/core/modules

mmjvb’s picture

To use the modules of drupal you need to specify the repository in your project:
`composer config repositories.drupal composer https://packages.drupal.org/8`

But, again, that is not the way to start. Pick a distribution and use `composer create-project ....` or look for the documentation to composerize.

meeks53113’s picture

hi mmjvb,

ive accessed the repository. i know because the prompts read 'installing' .. how do i get the installs where i need them?  i cant imagine composer already knows this. where is composer installing to? how can i pick up the installs?

meeks53113’s picture

C:\Users\002>composer require drupal/social_auth_google
Using version ^1.0 for drupal/social_auth_google
./composer.json has been updated
 

meeks53113’s picture

wait until it finishes then use the following command?

composer require "drupal/social_api:2.x-dev" "drupal/social_auth:2.x-dev" "drupal/social_auth_google:2.x-dev
mmjvb’s picture

You are heading for disaster!

meeks53113’s picture

ok, do you know someone who can everything fro me please?

i want people to be able to logon to my site using google password

meeks53113’s picture

how do i avoid disaster?

mmjvb’s picture

Depending on your requirements you can pick any of the available distributions. They all start with their own `composer create-project "package"`. When you want to start with bare Drupal start with package drupal-composer/drupal-project. The worst thing you can do is what you apparently did and start from scratch. You simply lack the expertise to do that.

bdupls’s picture

On root htaccess file add the following

RewriteEngine on

# Redirect to the subdirectory because that's where Drupal is installed
RewriteRule (.*) web/$1 [L]

In the setting.php file just above the database statement add - (You may need to change permissions to edit the settings file, just remember to switch them back to 0444.)

if ( isset($GLOBALS['request']) && '/web/index.php' === $GLOBALS['request']->server->get('SCRIPT_NAME') ) {
	$GLOBALS['request']->server->set('SCRIPT_NAME', '/index.php');
}

Now site will resolve correctly. 

jmoruzi’s picture

bdupls, unfortunately no, this doesn't work either. It just results in a 500 internal Server Error.

bdupls’s picture

Are you using https redirect in your .htaccess file? This script maybe interfering with the other redirects. Here is a sample, I don't like to use www, so you may need to change it slightly.

  # Force https with non www
  RewriteCond %{HTTPS} =off
  RewriteCond %{HTTP_HOST} ^yoursite\.com [NC]
  RewriteRule ^(.*)$ https://yoursite.com/$1 [L,R=301]
jmoruzi’s picture

bdupls, thanks very much for this, finally got it working with one minor change to www to non-www redirect in .htaccess. The problem with installing in the web directory has always been getting redirects to work. I think I followed the suggestions in this thread and a few others but they all suggest basically the same configuration. I could not get redirects to work without getting the web directory in the path after the domain name.

I tried your redirect code above, but the problem I was having is that your code only works if on http and www at the same time, if already on https and non-www the redirect to www does not happen. With your code in .htaccess in the web directory:

1. Redirecting http to https and www to non-www at the same time works

2. Redirecting from http to https works

3. If on https, there is no redirect from www to non-www (but no errors)

4. If I un-comment the default www to non-www redirect in .htaccess, redirecting www to non-www while already on https results in web being inserted into the path (https://www.domainname.com redirects to https://domainname.com/web) and a 404 error.

In my settings file:

if (isset($GLOBALS['request']) && '/web/index.php' === $GLOBALS['request']->server->get('SCRIPT_NAME')) {
  $GLOBALS['request']->server->set('SCRIPT_NAME', '/index.php');
}

In my .htaccess file in the public_html directory:

<IfModule mod_rewrite.c>
RewriteEngine on
# Redirect to the subdirectory because that's where Drupal is installed
RewriteRule (.*) web/$1 [L]
</IfModule>

In my .htaccess in the web directory I added your code:

# Force https with non www
RewriteCond %{HTTPS} =off
RewriteCond %{HTTP_HOST} ^yoursite\.com [NC]
RewriteRule ^(.*)$ https://yoursite.com/$1 [L,R=301]

But this does not redirect www to non-www if on https, it only redirects if on http and www so I also un-commented the default redirect code (this does not work):

# To redirect all users to access the site WITHOUT the 'www.' prefix,
# (http://www.example.com/foo will be redirected to http://example.com/foo)
# uncomment the following:
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]

But that results in the web directory in the path after the redirect, and the 404 error. The solution I was missing was to replace the default RewriteRule with the same RewriteRule used above. The boilerplate www to non-www code in .htaccess in the web directory becomes (this works):

# To redirect all users to access the site WITHOUT the 'www.' prefix,
# (http://www.example.com/foo will be redirected to http://example.com/foo)
# uncomment the following:
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://yoursite.com/$1 [L,R=301]

Remember to change yoursite to your actual domain name.

Perhaps someone who knows more about RewriteRules than I do can come up with a more elegant solution that does not require the domain name to be hard coded into the RewriteRule, but for me this is working for all redirect combinations of http, https, www and non-www.

Maplinx’s picture

I read with interest the responses to above issue. Reading through yours, it would appear you downloaded drupal using composer with the 'no-install' version and set it up in [public_html/web] instead of the default option <public_html/my_site_name_dir/web>? Or did you do the latter and migrated the web folder one step up into the public_html folder? I am wondering if your advice as to modifying .htaccess and settings files would work without migrating the web folder. Presently I have the error message 'no file found' - using the default install path [public_html (A)/project_folder(B)/webroot(C)]. One option I am trying to avoid is server side reconfig to point the document root to B or C. I was able to get this to work in localhost with IIS (creating a virtual path via application host config) but I may be missing something. I am yet to try the symbolic link option. 

vivekweb03’s picture

This works for me.

Thanks!

jshimota01’s picture

I'm here to thank the world for this thread. I'm developing in a WAMP environ under Win7.  I have 5 sites as sub-folders under the root of wamp (which is WWW - not docroot, public_html etc.)  The problem I see is this - if the composer.json file lives in the docroot (c:\wamp64\www) then how does composer manage multiple independent projects under it?  I mix/match my Apache and PHP to reflect my clients structures.  I'm trying to figure out the optimal folder structure, not just one that works.  Wouldn't it seem prudent to keep the composer.json out of the public structure or am I just burned out and missing the obvious?

<Rant> I crapped my environment.  Because of a module bug, drupal 8.8 was required for a module update (asset Injection) but I didn't know about the bug before I updated.  Prior to this bug being documented by the developer, I had already snapshot my environment then did my module updates BEFORE I moved from 8.7 to 8.8.  Update.php wouldn't run.  I had been using composer for some basic tasks, but my d8 wasn't a composer based install as is now suggested. 
Trying to recover got me nowhere so I attempted composizer and it failed. saying 'SMSGateway not found'. so I tried gocomposer. and my content went bad (add on libraries managed by composer gone). I tracked down what I had no idea of - composer files in my user\appdata\roaming folder of all places.  gocomposer failed with what look like OS errors "\" vs "/" OMG. what a mess! I couldn't go forward and couldn't go back.  Thanks D8.  2 hours coding, and 10 hrs debugging. I remember when ...

Now to go rebuild from scratch - you'd think after 14 yrs Drupal would be cleaner. </rant>

fkelly12054@gmail.com’s picture

Just an idea .... maybe have composer in each of your sites folders.  wamp64\www\site1 ... wamp64\www\site2 ... etc

That's what I kind of do to have independent environments, though I use a D: drive for my sites.  I have d:\webpage\drupal8 ... d:\webpage|drupcomp   ... then have virtual hosts set up in wamp pointing to each.  It's a bit of duplication but it might make your life simpler. 

Sorry about your difficulties.  Drupal is making a difficult transition to composer to deal with the zillion environments it needs to work in..

jshimota01’s picture

hmmm.  interesting.  my backups take forever, whats a few minutes more! (KIDDING). if I segment out the structure so there is no sharing.... interesting.  You'd think the .json would be named the same as the project. *shakes head*. that would allow me to stack the project names all at root, share the folder sub-structure that composer uses and keep redundancy to a minimum - at least in my mind that would be how it should work.  Sometimes I feel like I'm learned to write batch files again. again. again.

mmjvb’s picture

Obviously, composer only works on one composer.json, regardless its real name:
COMPOSER=site1.json composer install

Not convinced it is going to solve anything. Possibly for multisite environments. Normally there is one composer.json for a Drupal project. It is the limitation of composer that thinks on project level. A Drupal multisite setup helps to avoid redundancy, but doesn't keep it to a minimum. That would require manual work, probably your own build tools.

jshimota01’s picture

Thats a tidbit I did not know!  Where is that value kept?  Is there a composer.ini somewhere or is it a registry value?  If I rename the composer file to a site, keep it separated by site but under the main structure, I'd tie each .json to the project name and bob would be my uncle, it would be the ideal solution for me!  I had just thought that the composer.json was cast in concrete!

mmjvb’s picture

https://getcomposer.org/doc/03-cli.md#environment-variables

You can use it as mentioned above or set the environment variable COMPOSER in your shell:

export COMPOSER=site1.specification;

Obviously, site1.specification needs to contain whatever you have in composer.json.

Basiel’s picture

Hi,

thank you for this thread, but i'm still confused on this matter.
So I installed my site locally with composer : 

  • composer create-project drupal-composer/drupal-project:8.x-dev my_site_name_dir --no-interaction

With this, the root of my site is the "web" folder. Everything works fine.

I upload my site to my hosting server, were I have to put everything in the "www" directory. This can't be changed.
So what is now the best solution for my to be able to open my site. Change someting in the .htacces ? Or install my website a different way, so I don't have that "web" directory anymore. But then the "vendor" folder is in the same directory as the rest.

Sorry of this question is repeated, but I can't find the proper (easy :-) ) solution.

Thank you for your help,

Basiel

mmjvb’s picture

Take your loss and go to proper provider if this provider doesn't allow you to configure the DocumentRoot for your domain.

Yes, it is possible to have everything in the www folder, no, that is the worst solution, don't do it.

jmoruzi’s picture

mmjvb, can you provide some additional suggestions on how to configure a site after changing the doc root. I have a test site set up using the standard composer create project in the web directory and I have changed the doc root from /public _html to /public_html/web but have run into 2 issues so far:

  1. The boilerplate code in .htaccess to redirect from www to non-www now causes a 404 error with a redirect to domanname.com/404.shtml. I have the following code in my .htaccess code to redirect from http to https and it causes the same error:
     

    # To force http to https uncomment the following:
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

     

  2. Enabling Directory Privacy in CPanel now breaks the site with a 'too many redirects' error:

This page isn’t working

********.com redirected you too many times.

ERR_TOO_MANY_REDIRECTS

Any suggestions on how to proceed? Thanks.

mmjvb’s picture

The composer create-project needs a package of type project. The contents of that package determines the possibilities, which are unique to the package. They are all different: drupal/drupal, drupal-composer/drupal-project, drupal/recommended-project, drupal/legacy-project and each distribution providing their own: Lightning, Varbase, Open Social, Opigno, Thunder.

Normally, they use some kind of scaffold package to provide the files not part of drupal/core needed to install. The provided .htaccess should not cause redirect issues, one of the reasons I recommend setting DocumentRoot properly. Obviously, this assumes you followed instructions. Without the actual content that is hard to see. 

Few people know that sites are effected by .htaccess in any of the folders leading to DocumentRoot. They can cause redirect issues.

Sorry, not a CPanel user and no idea what Directory Privacy is about. Obviously, its name gives some idea, but it is the exact implementation that matters. I'll look into the documentation but can't promise anything.

Suggest to google on the error at drupal.org to see whether you can find issues resembling your setup.

jmoruzi’s picture

Thanks, I'll keep investigating and update when I find a solution.

nravens’s picture

Any luck with this?

My hosting company uses an index manager in their hosting console where I can set the location of the index.php file so it would be something like web/index.php but that changes it for all sites on that hosting account. So it breaks any site that isn't in a web/ directory.

I've tried the suggestions above and domain.com and domain.com/web opens the home page. navigating anywhere else on the site from that point will always have /web/something even going back to the homepage.

This composer installation just doesn't seem ideal for some hosting setups.

A manual installation of core doesn't require the /web directory. 

Does this mean going forward I won't be able to manage core updates with composer? or is that still a possibility?

mmjvb’s picture

When they don't allow managing your sites properly you might consider moving your business.

When the index manager works per hosting account, you need another one.

No, it is the other way around. Some hosting setups are giving you restrictions! You probably need to pay more for decent capabilities. 

Indeed the current distribution has everything in one folder. It is also ready for composer. Advice against it, but if you must use it, feel free to do so. Even your current setup could be adjusted to have everything in one folder. A matter of moving things around and changing composer.json.

nravens’s picture

Thanks for your feedback. I will indeed be looking at a different hosting option going forward if my current host isn't able to provide what I need.

I'm currently on a managed dedicated hosting package and I would have thought this meant being able to have things configured as I need. It's possible that I didn't properly explain what I need the last time I contacted support.

All our primary sites are on 1 dedicated hosting package so if going forward it's advisable to have all D8/D9 sites in a /web directory then it should work to have the server set that way, which i think is then doable using the index manager. 

Greenman77’s picture

Nakes,

I also run a dedicated CentOs server running WHM and cPanel for all of our customers both D7 and D8. I must say It makes me a little mad when we're told we need to use another hosting provider to run an Open-source CMS especially when cPanel would be the most popular platforms out there.  In your situation, you may have to but I don't think we should have to move off a cPanel type setup to have a running Drupal site.

I run D8 quite ok on my dedicated cPanel server with composer using the steps I've suggested previously in this thread; noting I don't use "require" or "update" on production only install and use a proper development workflow.

I will say setting up composer on a dedicated with cPanel is a bit of a pain and a time consuming from memory. It would have been lovely just using a pre-built server template configuration specifically for Drupal such as a container but we chose cPanel because of our long history on the platform.

On the positive, there are also loads of cPanel threads talking about this exact issue so I'm hopeful that changing docroot will get released as a feature upgrade at some stage so I don't have to continue to add the extra code to settings.php and .htaccess. 

Best of luck.

nravens’s picture

This is the reply I got from my hosting support:

"All our managed servers, shared and dedicated, make use of the same global setup which is not customizable. Should you wish to create your own unique environment perhaps you can consider our self-managed servers where you would create and manage all aspects of the server"

Also, they don't use cPanel. They have konsoleH

I think the composer installation is going to be a problem for many smaller companies who don't have the resources to run a self-managed server and big budgets for hosting.

jmoruzi’s picture

It's relatively simple to change the doc root from public_html to public_html/web in WHM/Cpanel as long as your hosting provider has the server configured to allow this. I have 2 VPS server, one with InMotion Hosting in California, the other with Web Hosting Canada in Montreal and both allow the doc root to be changed. However, I have another customer who's site is hosted on shared hosting with HostPapa and they are unable to reset the doc root due to all sites on the server using the same configuration.

On my VPS server, in WHM, I make the following changes in the Terminal, but keep in mind that depending on your hosting provider your mileage may vary:

Login to your cPanel account. Go to Server Configuration > Terminal. You should now be in the root directory so you need to navigate up one directory, and from there you should be able to navigate to any user account following the command below, replacing the “username” with your cPanel account username and “domain.com” with your primary domain name:

/var/cpanel/userdata/USERNAME/DOMAIN.COM

Find the following two lines in this file:

documentroot: /home/username/public_html
path: /home/username/public_html/cgi-bin

Change the documentroot of your primary domain from public_html to public_html/web, and the path to include the web directory. The document root and path should now look like this:

documentroot: /home/username/public_html/web
path: /home/username/public_html/web/cgi-bin

Save the file after changes are made and then delete the cache file for your primary domain:

# rm -vf /var/cpanel/userdata/username/domain.com.cache

If the primary domain has an SSL certificate installed you will need to modify the documentroot in the following file in the same way as above:

# vim /var/cpanel/userdata/username/domain.com_SSL

After your changes are complete save the file and then delete the cache for your primary domain:

# rm -vf /var/cpanel/userdata/username/domain.com_SSL.cache

After that’s done, you need to rebuild Apache and restart the server. Follow this for the exact command:

# /scripts/updateuserdatacache

# /scripts/rebuildhttpdconf
# service httpd restart

These instructions were taken from: https://www.buycpanel.com/1202015-changing-a-document-root-in-cpanel and edited for clarity and to make them specific to our situation.

One final change, I sometimes need to change the ownership of the web folder, permissions are set to 750, the same as the public_html folder, but I also change the ownership to nobody with the following command, remember to change "username" to your cPanel account username:

# chown username.nobody web

That's it, the web directory is now the docroot instead of public_html.

Basiel’s picture

Hi,

I have been able to solve this with a "symlink" on my hosting server. So I uploaded my entire site (create with composer, (web-folder)) on my hosting server in a sourcefile. With "ssh", I created a new path as hosting-sourcefile.

jshimota01’s picture

I never really followed further on this - since most of my sites I manage are d7, only 2 are d8.  I ended up creating a vm for the one site that doesn't really do much just for testing updates etc.  Just a thought for others - either use Oracles Virtualbox or in win 10 pro - hyperv (will require additional OS licenses after 90 days.)

stevensunsunsun’s picture

Hi,

I know this is an old thread but I'm having to exact same problem. Everything gets put in a web directory using composer create-project drupal/recommended-project public_html

I can't then navigate in my browser to my site's url and start the setup.

Please let me know if I'm doing something obvious wrong!

Thanks!

jshimota01’s picture

Maybe this suggestion may help if your open minded - " Don't fight it ".  It's older thinking that the 'root' of a website builds from the 'www'.  Depending on your web services - eg; Apache ... you tickle your http-vhost.conf file or something similar depending on your environment.  Here is an example of mine on my Dev machine in-house.  Production settings are different.  And below that I am providing my hosts. file which is related:

** Notice I leave the first one alone- in the case of my WAMP server this is where action from Wamp is managed. **

# Virtual Hosts
#
<VirtualHost *:80>
  ServerName localhost
  ServerAlias localhost
  DocumentRoot "${INSTALL_DIR}/www"
  <Directory "${INSTALL_DIR}/www/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require local
  </Directory>
</VirtualHost>

#
<VirtualHost *:80>
    ServerName bbi
    DocumentRoot "c:/wamp64/www/bbi/web"
    <Directory  "c:/wamp64/www/bbi/web/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

#
<VirtualHost *:80>
    ServerName test
    DocumentRoot "c:/wamp64/www/test/web"
    <Directory  "c:/wamp64/www/test/web/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

#
<VirtualHost *:80>
    ServerName rtb-nw
    DocumentRoot "c:/wamp64/www/bowlrtb/rtb-nw/web"
    <Directory  "c:/wamp64/www/bowlrtb/rtb-nw/web/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

#
<VirtualHost *:80>
    ServerName test-rtb-nw
    DocumentRoot "c:/wamp64/www/bowlrtb/test-nw/web"
    <Directory  "c:/wamp64/www/bowlrtb/test-nw/web/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

I have in my Host file (c:\windows\system32\drivers\etc\hosts:

# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host

# old 178.62.203.238 mf.svc.nhl.com
# 127.0.0.1 local.ultrasonicbowling.com
# 146.185.131.14 mf.svc.nhl.com

192.168.1.125    Camserver
127.0.0.1 localhost
127.0.0.1    bowlrtb
127.0.0.1    test
127.0.0.1    bbi
127.0.0.1    rtb-nw
127.0.0.1    test-nw

stevensunsunsun’s picture

Hi jshimota01,

Thank you for posting!

Wow, is this now the only official way to install Drupal 8? 

mmjvb’s picture

Setting the DocumentRoot for your domain has always been the correct way to configure your web server. Nothing new here!

What is new with Drupal is that not everything resides in the top folder anymore. At least with the recommended project. You can still have that with the legacy project. Unfortunately, that is not available for download. You need to use composer on the legacy project. The download gives you a recommended setup.

stevensunsunsun’s picture

Hi,

So I'm learning this from scratch … how do I set the DocumentRoot for my domain?

I'm using a temporary URL for the time being.

I have Terminal and shell access.

Please can you send me some steps! :)

Thank you!

mmjvb’s picture

Most providers give you an interface like Plesk or CPanel to configure the web server. Both should allow you to specify the DocumentRoot for your domains. 

The answer we are responding to gives an example of what should be done. Obviously, your situation is different. Without such an interface you would need to edit configuration files according to your desired situation.

Unfortunately, concrete instructions are depending on the implementation of your provider and your desired situation. None of them provided here.

stevensunsunsun’s picture

Hi,

I've have cPanel and also WHM access. I can also access via Terminal (Mac).

jshimota01’s picture

I'm loath to dig deeper on you since as the OP says - all vendors seem to differ these days. used to be cpanel was cpanel - now the vendors are customizing it and add the differing flavors.  Dont' get discouraged, work the problem 1 piece at a time and carefully go through the comments you've gotten here to implement what you learn here with what your environment is.  Godaddy is different than bluehost, which is different then siteground.

stevensunsunsun’s picture

Hello,

I'm using SingleHop but the cPanel is like the others.

I've changed my hosts files to point to the IP and created the addondomain however it is only loading a directory showing cgi-bin.

I've put the Document Root as /web

The Subdomain as web

And no redirect.

Have I missed a step?

stevensunsunsun’s picture

Hello, I've finally got this working with the help of the hosting provider, but now the website shows:

www.mywebsite/web

Is there anyway to remove the /web part?

Maplinx’s picture

It is still not clear to me if you needed to create an ADDON domain because you are having difficulty accessing the docroot from your project file in D8.5+ (cPanelUser/public_html/newsite_dir/web) OR because you needed a new domain address to point to your new site.

In my experience with D8.5+ installation, I found it easier with root access to point my docroot to 'cPanelUser/public_html/newsite_dir/web'. This way the /web part becomes your new 'public_html' root. I understand if you are using shared hosting this might be a problem. I did not need to create an addon domain in this instance as I needed to retain the primary domain name.

However if you needed to create an addon domain, different from the primary domain, then this is easier. Your addon domain should include the /web part as link to the file, I would think. The other option is perhaps to reconfigure your composer file (site_dir/composer.js) to point to include 'web' part appropriately. 

If any help this LINK might give you an idea of how I resolved my difficulty. 

Cheers

stevensunsunsun’s picture

Hello,

Thank for running through this explanation. In the end it just started to work without any issues apart from file permissions. Every time I install a new Module via composure I have to run find -type f -print0 | xargs -0 chmod 0644

jshimota01’s picture

Hi Steve - Glad to see you're still trying and making slow but steady progress.  It is a bit complicated but it's worth it in the end.
A few things you need to look at if you haven't already.  Verify you have docroot correct:  I tried to add a jpg example here but stupid web controls won't let me.  Basically you Point the domain name at the 'web' directory.

https://1drv.ms/u/s!AquG3DMW7H4-2hxQKHvt2qk5PVEU?e=NQ21MZ
 

Next - look at the rewrite and filesmatch xml in .htaccess.  Make sure you've not copied the file from the wrong place or overwritten or messed it up.  Here is a snippent

<FilesMatch "\.(engine|inc|install|make|module|profile|po|sh|.*sql|theme|twig|tpl(\.php)?|xtmpl|yml)(~|\.sw[op]|\.bak|\.orig|\.save)?$|^(\.(?!well-known).*|Entries.*|Repository|Root|Tag|Template|composer\.(json|lock)|web\.config)$|^#.*#$|\.php(~|\.sw[op]|\.bak|\.orig|\.save)$">
  <IfModule mod_authz_core.c>
    Require all denied
  </IfModule>
  <IfModule !mod_authz_core.c>
    Order allow,deny
  </IfModule>
</FilesMatch>

I also want to prepare you for a few other things you need to button down.   The new drupal complains if you don't set Trusted hosts.  My example:

# trusted host settings by JAS 1/15/20
$settings['trusted_host_patterns'] = [
  '^localhost$', '^192\.185\.52\.143$', '^rtb$', '^rtb-nw$','^rtb-nw\.bowlrtb\.com$',
#  '^localhost$', '^127\.0\.0\.1$', '^rtb$', '^rtb-nw$',
];

THe new drupal needs to have TMP and Privatefile folders set off the root or above it. Here is my 'above the root' setup:

# $settings['file_private_path'] = '';
$settings['file_private_path'] = '/home1/bowlrtb/public_html/privatefiles_rtb-nw';

and the last thing - I develop under wamp64 and setup Certs : here's a walkthorugh

https://statamic.com/forum/3718-wamp-windows-updater-issue-solved

stevensunsunsun’s picture

Hello,

Thank you for walking me through this.

So far I haven't needed to edit the .htaccess file.

For some reason it went from not working, to just working.

The main problem I'm facing now is that everything I install a Module with composure, the file permissions throughout the site change to 664 and result in a 500 internal server error.

I then have to keep running find -type f -print0 | xargs -0 chmod 0644

I've managed to stop the Installation failed error using #settings['skip_permissions_harding'] = TRUE; from here https://www.drupal.org/docs/develop/using-composer/starting-a-site-using...

…but I can't stop the files from all resulting in 664 permissions. Have you run into this issue?

jshimota01’s picture

I think thats user account related - but this isn't my area of expertise.  You mentioned you got some help from the ISP? maybe a question to ask them?

stevensunsunsun’s picture

Hi,

They have said that 'These permissions appear to be changed by the Drupal installation or anytime the modules are updated. You would either need to change the permissions as needed after module updates or contact Drupal for further support on this matter as it is their plugin that is causing this.'

jshimota01’s picture

My environment is development then push to production- so in my case I've never seen what you're seeing and never heard of others having the trouble.  Sorry I can't help more.

stevensunsunsun’s picture

Hi,

Yes, I'm doing exactly the same. Currently working in dev with hosts file to load via a URL and then will push to production.

SingleHop hosting the files. This was their last reply:

As previously mentioned you would need to talk to Drupal's support to resolve this as it seems to be some issue with their software causing this. We will, unfortunately, be unable to help with this software or issues it can cause.

mmjvb’s picture

The permissions are set in the package. Your environment causes them to be set for the server. Sounds like it is not properly configured, needing you to alter them. Just updated core and added a module with composer. Files are 644, so no need to alter them.

Could you verify umask? Mine is 0022. Suspect yours to be 0002.

Doubt very much the `solution` provided is correct. You shouldn't need to alter permissions! They are correct from the distribution. They might need adjustment for how your web server is configured. But, you shouldn't need to set them back to how they are provided. Only recall 1 time in the past archives were produced with wrong permissions. Swiftly corrected after reports of things being wrong. Haven't seen any of those reports lately. 

Also, depending on where you run that command, not all files need that permission.

stevensunsunsun’s picture

Hello,

I'm not sure what my umask is or how to check, but I put your post to SingleHop and they have said:

Our Team determined that something during Drupal's installation causes the files to be set to 664 which is causing your site's 500 error. From our investigation, it looks like something Drupal has done makes this directory change back to 664 every time something is changed. Outside of helping you change the permissions there isn't much more we can do as it seems this software is causing this. Either something in Drupal needs to be changed or you need to change your website's configuration to no longer need to execute permissions to function.

mmjvb’s picture

docker@cli:/var/www$ umask
0022
docker@cli:/var/www$

Not sure it has an effect in your situation. As mentioned, 644 are default permissions of distributions. Obviously, extracting them respects the environment settings. Sounds like your environment does more than you asked for. 

Haven't found composer options to influence permissions or the way to extract a distribution. Can you provide specifics about how you do things?

stevensunsunsun’s picture

Hello,

Yes, after accessing the account using Terminal on a Mac and entering my password:

1. cd public_html

2. Install Module for example; composer require 'drupal/ctools:^3.4' 

3. Navigate to http://www.mysite.com/admin/modules

4. –500 internal server error–

5. Back to Terminal; find -type f -print0 | xargs -0 chmod 0644

6. Navigate to http://www.mysite.com/admin/modules and Install the Module

I have to do this every time that I use composer!

mmjvb’s picture

or inspect logfiles: 500 internal error is useless. It tells you to find out what was wrong. Enabling error reporting could give you an idea what is really wrong.

Wonder what the permissions are after step 2 for the module just downloaded. Also step 1 and 5 already causes you problems of wrong permissions. Despite it fixing the issue it is causing you other issues you haven't discovered jet. 

Again what is your umask?

stevensunsunsun’s picture

Hi,

The umask is 0002.

I've enabled logging and errors and installed a Module. The permissions for that Module were Ok after install.

But all of the files in the /web dir changed again to 664.

Here's before: https://prntscr.com/rv08q8

Here's after: https://prntscr.com/rv08xc

There were no new errors in the Recent log messages.

mmjvb’s picture

You might want to try the require with -vvv

In my case it showed a very simple unzip command:

  - Installing drupal/composer_forced (1.1.0): Reading /home/docker/.composer/cache/files/drupal/composer_forced/a6fa5c737797f77bf949d1a74ac58d7bff015552.zip from cache
Loading from cache
 Extracting archiveExecuting command (CWD): unzip -qq  'web/modules/contrib/composer_forced/387166a93701056f9372f76fe8ae884b.zip' -d '/var/www/vendor/composer/8c46c43f'
    REASON: Required by the root package: Install command rule (install drupal/composer_forced 1.1.0)

Setting umask to 0022 might leave those file permissions alone. Your composer.json might also be relevant. No idea why something would apply umask. Those needing 0002 would probably like that. Did your provider confirm the need for umask 0002 ?

To me, it sounds your umask is wrong and should be 0022.

EDIT: Also the files below web/sites/default/files might require different permissions. Would exclude them from your command when you don't fix the real issue.

stevensunsunsun’s picture

Wow thank you so much!! They have made this change and now the permission don't change. Finally :)

Now I just have to check everything and fix any permissions I may have changed running find -type f -print0 | xargs -0 chmod 0644

mmjvb’s picture

What I still wonder about is what is doing that change of permissions. Haven't found code in composer that is responsible for it. Could you share a `composer require .... -vvv > req.log` to investigate? Post req.log here or send it privately using my contact page.

stevensunsunsun’s picture

Yes, sorry but I'm slowing learning composer. What should go after composer require:

composer require .... -vvv > req.log

mmjvb’s picture

Adding `-vvv > req.log` to your require command normally.

-vvv : provides debug information 
> req.log : redirects screen output to the file req.log. You can name it what you want (log.txt, req.txt). The contents of req.log is what I am interested in. I would like to figure out what causes the file permissions to be altered. Note that you need to make sure in Terminal that umask is 0002 as it was when you had this issue. 

$ umask 0002
$ umask

The command umask reports its value, adding the value sets it to that value.

The package on the require must be one that is not used jet. Or removed first. You can check with `composer show`. Only remove packages not enabled jet/anymore.

stevensunsunsun’s picture

Hello,

Ok, I've done that will try and send to you privately. It's a short file. There was a great deal more info in the Terminal window also.

stevensunsunsun’s picture

Hi,

Did the log reveal anything?

mmjvb’s picture

It was what you received in your Terminal session that I was after. Maybe you can repeat the command with error redirection. That is: 2>&1 added to the command.

stevensunsunsun’s picture

Hi, yes I saved that separately – will send to you now.

chike’s picture

All our clients so far use Cpanel so long time I thought about this and I found a way to make the setup. What we do is we make a 'modified install' which initiates the project (creates composer.json and composer.lock) but does not download Drupal and the dependencies yet. We will be doing this on Cpanel root away from public_html (it's recommended to place composer.json and vendor away from the web-root), so we will now edit composer.json and change the web-root and installer-paths from 'web/' to 'public_html/', save the file and run 'composer install'. Drupal will be installed in public_html easy. I explain this in more detail in my blog post, https://www.skillmaticace.com/blog/how-install-drupal-8-composer-cpanel