Skip to main content

Configure installed Drupal to run from domain root

Configure composer to install Drupal directly into hosting provider document root istead /web

In this example - I using Laragon & project install to: www

Method 1: Configure During Initial Installation

Step 1: Create project without installing dependencies

composer create-project --no-install drupal/recommended-project "my-project"

Step 2: Edit composer.json

Change web root from web/ to your document root (e.g. public_html/ for cPanel).

Find the "extra" section

change from "web-root": "web/" to "web-root": "public_html/"

"extra": {"drupal-scaffold": {"locations": {"web-root": "public_html/"}},"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"],"public_html/modules/custom/{$name}": ["type:drupal-custom-module"],"public_html/themes/custom/{$name}": ["type:drupal-custom-theme"]} } 

Step 3: Install dependencies

Place the terminal in the document folder - example: www\my-project &

run composer install

Drupal core files will now be installed into public_html/ instead of web/.

When to install drupal use this format: localhost/yout_project_name/publib_html


Method 2: For Existing Installations

If you already have a Composer-installed Drupal site in /web:

  1. Backup your current installation
  2. Edit composer.json — replace all web/ paths with public_html/
  3. Reinstall
  4. Move custom files/config from /web into /public_html

Hosting Provider Considerations

  • cPanel hosting → usually requires public_html/
  • Other shared hosts → might use htdocs/ or www/
  • VPS/Dedicated → you can point Apache/Nginx to /web instead of renaming

Always confirm your host’s expected document root.

Security Benefits Maintained

This approach keeps all the Composer security advantages:

  • vendor/ stays outside the web root
  • Config files remain protected
  • Core files are managed by Composer
  • Custom code is neatly separated from core

Alternatives

1. Symbolic Links (if supported by your host)

# Create symlink from public_html to web directory ln -s web public_html

Many shared hosts disable symlinks for security reasons.

2. Web Server Configuration (if you control Apache/Nginx)

Apache: DocumentRoot /path/to/your/project/web

Nginx: root /path/to/your/project/web;

The custom web root configuration (Method 1) is the cleanest solution because it:

  • Eliminates the need for redirects or server tweaks
  • Preserves Composer’s security benefits
  • Works with any hosting provider’s document root structure
  • Keep your site accessible at example.com instead of example.com/web

This approach is widely used in the Drupal community, especially for shared hosting environments where you can’t modify server configs.

mkdir public_html
composer install
composer install
composer create-project --no-install drupal/recommended-project my-projectcd my-project

Google AdSense
client = ca-pub-2898279488603899
slot = 9058461004
format = auto