0

I have a Drupal site installed via composer, creating a structure like

vendor/
config/
composer.json
etc/
web/core
web/themes
web/index.php
web/etc

Is there a way to change the web folder to a public_html folder so I can use it on my hosting? So the structure needs to be:

vendor/
config/
composer.json
etc/
public_html/core
public_html/themes
public_html/index.php
public_html/etc

I got it working now by using .htaccess but I started using this method with the config outside of my root folder because of the security advantages. With this method, the config is still in my root but via htaccess I point everybody to the web folder. Is this still secure enough?

So how can I change this and is it necessary?

8

You should be able to change the installer paths in composer.json, which defines where the files are placed:

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

to:

"installer-paths": {
  "public_html/core": ["type:drupal-core"],
  "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/contrib/{$name}": ["type:drupal-drush"]
},

You can then rename the web folder to public_html and everything should work.

| improve this answer | |
  • I don't know if it was necessary but I did a composer update after the change. But it works perfectly! – Joost Dec 11 '17 at 13:05
  • I tried this, but I reinstalled had to change a line in scripts/ as well. – petergus Jul 1 '18 at 9:07
  • 1
    When changing the paths on an existing installation, use composer dump-autoload for updating the autoload files to make it work once the paths are changed. – conceptdeluxe Oct 23 '18 at 21:01
0

The steps to install Drupal in public_html is to make a 'modified install', this means initiating your project with this composer create-project drupal/recommended-project my_site_name_dir --no-interaction --no-installThis will initiate Drupal 9, if you want Drupal 8 instead then use this composer create-project drupal/recommended-project:^8 my_site_name_dir --no-interaction --no-install

The --no-install flag will stop the installation of Drupal upon project initiation.

You should be in your Cpanel root (one step away from public_html), this will initiate your project inside my_site_name_dir directory. Cd into the directory and move composer.json and composer.lock up inside the Cpanel root, move back to the root and delete the now empty my_site_name_dir directory.

Open composer.json in an editor and change the web-root and installer-paths from 'web/' to 'public_html/', save the file and from Cpanel root run composer install.

Drupal will be installed inside public_html and you can access your site on site.com without any sub-directories. Also vendor folder and the Composer files will be placed away from your web-root (public_html) which is the recommended setup.

I explain this also in my blog post, https://www.skillmaticace.com/blog/how-install-drupal-8-composer-cpanel

| improve this answer | |

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.