You are here

Drupal 8: create a "files" directory in root

I've always found cumbersome and inefficient the default file system for drupal:

Drupal is flexible of course and you can put your files anywhere you like. I prefer to have my files in root, like this:


For this particular configuration you need to do the following.

1. Create a "files" directory in root (so that "files" sits alongside scripts, modules, sites, core, etc.)

2. If you are in a multisite environment working from a single codebase, create within the "file" directory individual folders, each of which correspond to one of the multiple sites you are running. For example, if I had a site, I'd create under "files" a discreet folder called, for example, "d1" which would be dedicated to just that single site.

3. Go into the "sites" folder in root and open the folder entitled Adjust permissions on settings.php so you can edit it. Specify the new location of your files by uncommenting the last line below and editing it to read $settings['file_public_path'] = 'files/d1';.

* Public file path:
* A local file system path where public files will be stored. This directory
* must exist and be writable by Drupal. This directory must be relative to
* the Drupal installation directory and be accessible over the web.
# $settings['file_public_path'] = 'sites/default/files';

4. Important: change permissions on settings.php to 404.

5. Now clear your cache and navigate to admin/config/media/file-system and you should see your new path in the first line. (Note: if you have selected a custom color for one of Drupal's built in themes such as Bartik, you will likely need to go into Appearance, select the theme you are using, and then reset the color profile. I have found that this is the only way to restore the "color" folder to the new file location; clearing the cache does not suffice.)