1

We have a client with simple request to move the Public File folder up simply so that links will be shorter like example.com/files/ instead of example.com/sites/default/files/.

I assumed this would just entail running

mv ./sites/default/files/ ./files/

in the root directory where my index.php resides and then changing the line in settings.php. Yet, this does not work, and I can't figure out why. In the file_managed table the uri column looks like public://example.png. Does that variable 'public' not resolve to the default public path?

Here's what my settings.php line reads:

# Change Public File directory
$settings['file_public_path'] = 'files';

The folder is right next to my index.php file and the entire folder, including contents is set to 775, or rwxrwxr-x.

drwxrwxr-x. 47 apache webgrp  28672 Nov 15 10:14 files
-rwxrwxr-x.  1 apache webgrp    648 Oct 25 08:17 index.php

Weirder, in the browser inspector, it appears that Drupal is looking for files at /files/example.png and there is definately a matching file at /files/. What am I missing? The only docs I can find are for Drupal 7, and all modules I've seen are only for 7 as well.

2 Answers 2

3

Look in Admin > Config > Media > File System:

/admin/config/media/file-system

Public file system path sites/default/files 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. This must be changed in settings.php

So there you have it. If you want to change the file system path for the public:// stream wrapper, you will need to edit settings.php.

EDIT: I'm not sure what else is at play here. If you still can't get this working to your client's specifications, you may be able to spoof it with a symbolic link in the file system:

ln -s files sites/default/files

The files would still be hosted in the wrong location, so this is actually no solution. Hopefully somebody else can point you in the right direction. Good luck!

3
  • 1
    Same question then: I updated my answer to show what the settings.php file contents and mention the permissions should be fine. What else needs to get changed? Dec 3, 2018 at 21:24
  • 1
    It's a Drupal cliche, but "Did you clear the cache?" Dec 3, 2018 at 23:27
  • 1
    Cache was cleared. Both through admin panel, through drush with drush cr and in Chrome turning on the 'Disable Cache (while Developer tools are open)' setting. Dec 3, 2018 at 23:34
1

Doing just a mv move command isn't enough. You need to set the public file path in the admin to a path accessible by the application.

In the files table, public:// is a stream wrapper which will resolve to the public files path, but only if you have updated this configuration. Moving the files, it does not know about it.

Check that you've named the variable correctly in settings.php and also change it in the admin screen and verify both. The folder needs to be readable and writeable as well.

3
  • Where is the admin page you are referring to? I changed it in settings.php via copying it from the default.settings.php. Looking under the Configuration->Media->File Systems menu shows that it detects the new public path is just files and because the folder already had the correct permissions to read and write, I assume that I shouldn't need to update this (ls -al tells me that the entire folder/contents are set to 774, so that shouldn't be an issue) Dec 3, 2018 at 21:14
  • /admin/config/media/file-system
    – Kevin
    Dec 3, 2018 at 21:21
  • It reads "This must be changed in settings.php" and is already correct at just files. Updated my question to show that the folder exists and has permissions. So what else is left? Dec 3, 2018 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.