0

I used to have a Drupal 7 installation on var/www, but I had to move it to var/www/drupal. The problems is that my files are still in var/www/sites/default/files and I am unable to move them.

I need to make Drupal use that directory as default file directory (just on level above). On admin/config/media/file-system, I tried to use absolute file path, without success. I tried to set ../sites/default/files too; it was almost successful, but now I am having problems with the image creation and caching. I have to manually load every single image style; otherwise, it does not find the file.

How can I set up a public file folder which is one folder above Drupal's root folder?

3 Answers 3

1

You can maybe create a symlink of /var/www/sites/default/files to /var/www/drupal/sites/default/files. Assuming you're inside /var/www/drupal, the command to do that is:

ln -s ../sites/default/files sites/default/files

So with this in the File System configuration page, you can just use the default path "sites/default/files".

But you can also just transfer /var/www/sites/default/files into it's new and final location though just to make things cleaner and organized, if you want.

Updated

Since you have noted also that "../sites/default/files" almost worked maybe you just need to update the permissions of the folder to maybe 775 and try to clear caches.

Hope everything works for you.

7
  • Thank you for your answer. I tried to make symlink, but I think I have no right to create link on my ftp. I get error message "500 Unknown Command". Btw, I have access to cpanel, but I did not find such option. Moving files are impossible. I would do it, becuase as you said it makes everything more clean and orgnaised, but its simply impossible. I have to figure out something else. Dec 6, 2015 at 15:36
  • No problem at all. I have update my answer also with a small task and checking that you might be allowed to do. It's regarding the ../sites/default/files permission maybe Drupal isn't able to write stuff in there. Dec 6, 2015 at 16:12
  • It has 775, caches all cleared were often, because am working on this site. Currenlty the public folder is set to "../sites/default/files". Most of the files do work, but when am editing a note and I am inserting an image to the node's body with Insert module, the photo's url is broken. As I also experienced (with this public folder setting) my other image urls break sometimes and I end up showing no image. Dec 6, 2015 at 16:30
  • Okay, I played around again. So it uploads the image to the right directory. I can use the orignial file. I dont have issues anymore with non image files. The current problem is: drupal is unable to create the image style. Eg: I would like to use drupal's original medium image style. It does not create it. If I want to use the original image, it has no problem. Its in the right directory. Dec 6, 2015 at 16:38
  • That might be an issue regarding permissions again for the ../sites/default/files/styles folder. How about trying to apply the permission recursively into the files and folders inside ../sites/default/files. Check also the System Report, Recent log messages pages foe any errors maybe that would give you some more clues. But that might be some configuration issues already that may not be relevant to the files issue w/c may be solved already. Dec 6, 2015 at 16:38
0

Change the file path from drupal configuration and the clear the cache and rebuild the registry.

5
  • Currently its set to $conf['file_public_path'] = '../sites/default/files'; and it makes image style caching issues. Dec 6, 2015 at 18:30
  • Don't use '..' because is relative path. And don't set the path from setting.PHP file. Set it from Drupal ui (admin/config/media/file-system) and then clear the cache and rebuld the registory.
    – Prem Patel
    Dec 6, 2015 at 18:41
  • admin/config/media/file-system sadly only allowes relative paths Dec 6, 2015 at 18:43
  • Yes ... put the file folder under site default folder.
    – Prem Patel
    Dec 6, 2015 at 19:25
  • I cant. That would be the easiest solution, but i can not do that. Dec 7, 2015 at 0:02
0

After many hours desperately looking for a solution to override the public file path, I managed to find a better solution.

At admin/config/media/file-system changed back to default settings sites/default/files and added some extra line in the .htaccess file of drupal's root directory.

RewriteEngine on
RewriteRule ^sites/default/files/(.*)$ /sites/default/files/$1 [NC, L]

So this perfectly redirects example.com/drupal/sites/default/files/foo.jpg to example.com/sites/default/files/foo.jpg

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.