Skip to main content
Menu
Offcanvas

Rename "web" public folder to htdocs, public_html or other

The folder that contains the public site is named web. It may happen that we are asked to rename it.

Installing Drupal with Composer

After installing Drupal 9 with for example this command:

composer create-project drupal/recommended-project my_site_name_dir

Rename web folder to htdocs

We must first modify the “extra” section in the composer.json file, run the dump-autoload command and manage the configuration of the domain / vhost to point to this new folder.

After installing the files, open the composer.json and replace these lines:

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

by (you can do a find/replace of "web" folder name and replace it with "hotdocs")

"extra": {
        "drupal-scaffold": {
            "locations": {
                "web-root": "htdocs/"
            }
        },
        "installer-paths": {
            "htdocs/core": [
                "type:drupal-core"
            ],
            "htdocs/libraries/{$name}": [
                "type:drupal-library"
            ],
            "htdocs/modules/contrib/{$name}": [
                "type:drupal-module"
            ],
            "htdocs/profiles/contrib/{$name}": [
                "type:drupal-profile"
            ],
            "htdocs/themes/contrib/{$name}": [
                "type:drupal-theme"
            ],
            "drush/Commands/contrib/{$name}": [
                "type:drupal-drush"
            ],
            "htdocs/modules/custom/{$name}": [
                "type:drupal-custom-module"
            ],
            "htdocs/profiles/custom/{$name}": [
                "type:drupal-custom-profile"
            ],
            "htdocs/themes/custom/{$name}": [
                "type:drupal-custom-theme"
            ]
        },

Regenerate autoload declarations

You need to regenerate autoload statements. To refresh autoload from composer, run the command:

composer dump-autoload

Résultat

This is what this command returns:

Generating autoload files
Generated autoload files

Conclusion

You will then need to point the domain to this new folder and your site should be up and running.

Other useful resources

Add new comment

Similar blog posts

How to delete local changes with git that you haven't committed ?

LIRE LA SUITE