You are here

Drupal 8: create a "files" directory in root

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

http://domainname1.com/sites/domainname1.com/files

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

files/d1

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 domainname1.com, 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 domainname1.com. 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.