Drupal with Composer, on hosting environment like GoDaddy

Submitted by fishfin on Sat, 01/12/2019 - 03:49

I am a big fan of using Composer to manage Drupal 8. This type of Drupal installation uses "web" directory from which the Drupal index.php, and the rest of the code (core, modules, libraries) is served. However, a GoDaddy hosting space uses "public_html" as the document root for the GoDaddy primary domain. To make the composer installation work with this, the fix is rather simple.

The Fix

Follow these steps in the same order:

  1. In composer.json, under segment "installer-path", you will find entries starting with "web/". Change them to "public_html". For example, after the change it should look like:
            "installer-paths": {
                "public_html/core": ["type:drupal-core"],
                "public_html/libraries/ckeditor_codemirror": ["npm-asset/ckeditor-codemirror-plugin"],
                "public_html/libraries/colorbox": ["npm-asset/jquery-colorbox"],
                "public_html/libraries/easing": ["npm-asset/jquery.easing"],
                "public_html/libraries/jquery.hoverIntent": ["npm-asset/jquery-hoverintent"],
    			"public_html/libraries/json2": ["npm-asset/json2-browser"],
                "public_html/libraries/slick": ["npm-asset/slick-carousel"],
                "public_html/libraries/{$name}": [
                    "type:drupal-library",
                    "type:npm-asset",
                    "type:bower-asset"
                ],
                "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"]
            },
  2. Rename "web" directory to "public_html".
  3. Run "composer update" again. You may receive a message "Nothing to install", its okay, the change of directories has been registered now.
  4. In your local environment (if you have any), change your web root from "<drual_install_dir>/web" to "<drupal_install_dir>/public_html". Your new directory structure should look like the following (don't worry if it doesn't exactly look like it, this is just an example):
     [D] <drupal_install_dir>
      |_ [D] config
      |_ [D] drush
      |_ [D] public_html
      |_ [D] scripts
      |_ [D] vendor
      |_ .editorconfig
      |_ .env
      |_ .env.example
      |_ .gitattributes
      |_ .gitignore
      |_ .htaccess
      |_ .travis.yml
      |_ composer.json
      |_ composer.lock
      |_ LICENSE
      |_ load.environment.php
      |_ phpunit.xml.dist
      |_ README.md
    

Your GoDaddy hosting will give you access to one level above "public_html". FTP the <drupal_install_dir> to that directory. That's it, you now have Drupal being hosted out of "public_html".

Thanks for visiting!