Composer puts a new D8 site's web server root in siteroot/web. Most cPanel shared and reseller hosts insist on the web server root at ~/public_html. I've thought about deleting or renaming ~/public_html and creating a symbolic or hard link to siteroot/web, but I don't know what trouble that could get me into. One sales chat rep said I could ask tech support to set my root. The others all said VPS, which requires more management than I care to do and more $ than a reseller shared account.

Is there a reasonable way to tell Composer to cooperate with ~/public_html? Are there reliable entry-level reseller shared hosts with room to grow that let me say the web server's root is siteroot/web?

Comments

sprite’s picture

Perform your base d8 install WITHOUT composer, then setup composer afterward.

Get your SSH access setup first.
- make sure your host provides adequate PHP memory limit (otherwise you will get php/composer errors)

1. download the D8 core .zip to the docroot ~/public_html/
or if you define a sub domain or add on domain:
~/public_html/{sitedomainname}/

- - keep in mind that you can probably run multiple instances, domains, subdomains, on your hosting account.

2. setup database via phpmyadmin
- Do NOT modify the settings.php

3. Run {site}/install.php
- enter DB credentials.
- install finishes.

4. Via SSH, run "php composer.phar install" in your ~ (home) directory (the .. above public_html).
- the composer install will create a .composer directory below your ~ (home) directory.

5. put a copy of composer.phar in the /public_html/ or ~/public_html/{domain}, as the case may be.

6. Run "php composer.phar update" in the docroot directory of the drupal site (there is a composer.json there).

7. Note - you may want to move the drupal/core directive from the "replace" section to the "require" section.
- set the version to "^8.3" for now, and then change to "^8.4" once the bigger version release occurs.

8. Add all module code to your site using composer!
- php composer.phar require drupal/{modulename}
- - composer will figure out appropriate available version by itself.
- - - After composer module code install, you "enable" the module from the Drupal admin extend GUI.

------------------

Keep in mind that some Drupal distributions come with a "pre-installed" code base and an existing pre-populated SQL database. Those can be installed by importing the database via phpmyadmin, unzipping the code in the site docroot, and running {site}/install.php to update the database credentials (make sure the settings.php doesn't exist before running install.php).

(example of the type of drupal distribution described just above)
https://github.com/morethanthemes/showcase-lite

The distribution type just above is a better beginner way to start with Drupal because it comes with a nice looking theme and default content already installed for provide examples of how to do things.

spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...

AES2’s picture

I've been distracted by a bunch of other stuff over the past few weeks and was finally able to get back to this. I've been active in other communities and never received the outstanding level of replies that I've gotten from Drupal the few times I posted questions.

Thanks, Sprite! This makes a lot of sense!

nick_cooper’s picture

We could not find a solution to this problem.
Thank you for the detailed answer.

Best regards,
Nick Cooper - https://develux.com

onejam’s picture

In your cpanel, you can try and use 'Redirects' feature and to redirect main domain to your sub directory.

Otherwise, move your complete site to public_html directory and follow this guide to get composer working inside of your existing site: https://duvien.com/blog/managing-existing-drupal-8-site-composer (every Drupal installation has a composer.json file already in place. You just need to make a few alterations and you are good to go).

-----------------------------------------------------------------
We build engaging websites and intuitive designs that will benefit your business.
Duvien

sprite’s picture

What will work in cPanel is a subdomain.

Create a subdomain like:

www.mydomain.tld

and on the subdomain setup screen set the directory as:

/public_html/www.mydomain.tld/

- - which fully qualified is actually ( /home/{username}/public_html/www.mydomain.tld/ )

Then

/public_html/www.mydomain.tld/

is the docroot for the site. Depending on WHM settings, you may need to edit the .htaccess to tell it not to add another www onto the explicit www already defined.

I use WHM/cPanel on a VPS and do this to setup an unlimited number of domains and subdomains with an unlimited number of Drupal instances for development and testing.

spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...

AES2’s picture

Adding Duvien's response to Sprite's makes it really easy to understand, and the subdomain idea is also interesting. Thanks both of you!

mchaplin’s picture

Rename public_html to public_html_old

ln -s {composerfoldernameyouchose}/web/ public_html

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

onejam’s picture

You can use htaccess file to redirect /public_html directory to /web I wrote an article on how this can be done on a shared hosting platform without having to fiddle around with more extra work. Here's the article (scroll to near the bottom to see the explanation and code) - using htaccess to redirect to /web to serve as the main web root. Any files in your /public_html will now be treated as outside of the web root.

It's fine change the path to /web in composer.json to /public_html. It will work just as well but i tend not to like having my drupal stuff all mixed up with other server files and directories in home directory. So this method using the htaccess file keeps it clean. Also, supposing you had a few other Drupal sites installed on the same server, there will be conflicts with your composer.json files, unless you can rename these files to work?  

-----------------------------------------------------------------
We build engaging websites and intuitive designs that will benefit your business.
Duvien

chike’s picture

In my solution you only edit 'web/' to 'public_html' once and for the life of the site nothing to tamper with again. Also I usually do this in development environment 'cos I start my projects locally before moving to live server. So on my laptop I will create a folder for the project with a public_html folder in it (to copy the folder structure in Cpanel), I will then initiate the project in the project folder and edit Composer files to install inside the public_html folder (which is exactly how it's structured in Cpanel). So while moving to live server I do not make any more changes, I move the site and it works straightway on live. I will copy the Composer files to the root of Cpanel, copy sites folder and other custom folders and files (leaving out everything installed with Composer), then on live I will run composer install --no-dev and straightway Composer will place exact copies of vendor folder, contrib modules and themes as was in the local copy. So I will move the site to live neatly without adjusting anything again. Also I can move the site to any other domain and straightway it's working.

Compare with your own solution, I will have to memorize .htaccess rewrite rules and the code for settings.php. If I am installing a new site and I can't remember how exactly they are written nor find where I wrote them down then I get stuck. If I move from local to live I start tampering with code, if I move to another domain I start changing hostnames, if my settings.php or .htaccess file gets overwritten then site will break and if I can't find where I wrote the rewrite code down the site will stay broken.

So which solution is neater.

As for putting vendor in home directory, you will also have private folders placed there so you will have something there anyways.

As for having other sites on the server, I have battled with this a few times, most shared host will nest addon domains inside public_html and it gets messy so having multiple sites on the server will be best fit for a VPS and with a VPS you will rather make separate Cpanel accounts and each site has its own public_html so my solution still applies here.

Haha.

onejam’s picture

Well, if it works for you and you find it easier to maintain with your own workflow, then i'll stick with it. Everyone has their own way of working. The way i did it made sense to me to keep everything neatly in its own folder (nothing wrong with also keeping the /private and /config directories in the same folder outside of /web). As for memorizing, i never remember any code i write but i keep a backup copy of everything i do. 

Either way, the best and recommended solution would be to create a vhost in your Apache config file. Unfortunately, this is shared hosting environment. 

...VPS you will rather make separate Cpanel account...

Again, you can setup multiple different domains using vhost, no need for separate cpanel accounts. 

-----------------------------------------------------------------
We build engaging websites and intuitive designs that will benefit your business.
Duvien

chike’s picture

Okay, thanks. I will check about vhost in Apache.

sushi2121’s picture

Cool!