Skip to main content

Drupal 8 - Rename public directory from web to public_html

If you use composer for Drupal 8, default you have your public data inside web directory. To change that, you need to edit composer.json and find extra section:

    "extra": {
        "installer-paths": {
            "web/core": ["type:drupal-core"],
            "web/libraries/{$name}": ["type:drupal-library"],
            "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"]
        }
    }

Change web, to your directory, for example public_html. So composer.json become:

    "extra": {
        "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/contrib/{$name}": ["type:drupal-drush"]
        }
    }

You need to regenerate autoload declarations. To refresh autoloading from composer, run command:

composer dump-autoload

Run your website, should works fine if you renamed /web to /public_html

Short checklist in case of any problems:

  1. Rename folder /web to /public_html
  2. Modify extra section in composer.json
  3. composer dump-autoload
  4. Setup domain/vhost to point on a new folder and reload server configuration if needed

Add new comment

CAPTCHA

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

We use cookies on our website to enhance your user experience. We also use Google analytics and ads.

Click here to read more I've read it