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?

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.

  • 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. – Márk Cserepes Dec 6 '15 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. – Leolando Tan Dec 6 '15 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. – Márk Cserepes Dec 6 '15 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. – Márk Cserepes Dec 6 '15 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. – Leolando Tan Dec 6 '15 at 16:38
0

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

  • Currently its set to $conf['file_public_path'] = '../sites/default/files'; and it makes image style caching issues. – Márk Cserepes Dec 6 '15 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 '15 at 18:41
  • admin/config/media/file-system sadly only allowes relative paths – Márk Cserepes Dec 6 '15 at 18:43
  • Yes ... put the file folder under site default folder. – Prem Patel Dec 6 '15 at 19:25
  • I cant. That would be the easiest solution, but i can not do that. – Márk Cserepes Dec 7 '15 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, privacy policy and cookie policy

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