johndoe3226
Posts: 20
Joined: Tue Oct 03, 2017 10:37 pm

Store all website files into an external drive

Sat Dec 16, 2017 8:05 am

I want to store all my web files into an external drive so that it is not in the default /var/www directory. I have a default apache installation and the external drive is formatted using windows so I install ntfs-3g.

I need to do this because I will be storing large files and my sd card won't be big enough.

Reading around this forum, it seems that I need to change the directory in httpd.conf to point to my external drive, how do I do that?

Also I need to automount my drive on boot.

I appreciate any help from you guys. :)

jahboater
Posts: 2632
Joined: Wed Feb 04, 2015 6:38 pm

Re: Store all website files into an external drive

Sat Dec 16, 2017 8:16 am

I don't suppose a soft link would do?

ln -s

User avatar
rpdom
Posts: 12500
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: Store all website files into an external drive

Sat Dec 16, 2017 8:26 am

Change the mount point of the external drive to be /var/www/html ?

johndoe3226
Posts: 20
Joined: Tue Oct 03, 2017 10:37 pm

Re: Store all website files into an external drive

Sat Dec 16, 2017 8:41 am

rpdom wrote: Change the mount point of the external drive to be /var/www/html ?

What fstab do I need for that?

EDIT: Reading around though, it seems to be hard coded in the source and can't be changed, I'll try to link it by ln -s
Last edited by johndoe3226 on Sat Dec 16, 2017 9:02 am, edited 1 time in total.

johndoe3226
Posts: 20
Joined: Tue Oct 03, 2017 10:37 pm

Re: Store all website files into an external drive

Sat Dec 16, 2017 8:59 am

jahboater wrote:
Sat Dec 16, 2017 8:16 am
I don't suppose a soft link would do?

ln -s
So I do ln -s /dev/sda1 /var/www/html?

johndoe3226
Posts: 20
Joined: Tue Oct 03, 2017 10:37 pm

Re: Store all website files into an external drive

Sat Dec 16, 2017 9:24 am

I tried linking it by ln -s /some/directory /var/www/html

A link is created but the content of my website is not present, I now see a link at /var/www/html but when I reload my webpage, it shows nothing.

What am I doing wrong?

User avatar
rpdom
Posts: 12500
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: Store all website files into an external drive

Sat Dec 16, 2017 9:33 am

The default mount point of a drive may be hard coded, but should be able to be overridden in fstab.

You could change the default location in the webserver config. Which webserver are you using?

johndoe3226
Posts: 20
Joined: Tue Oct 03, 2017 10:37 pm

Re: Store all website files into an external drive

Sat Dec 16, 2017 10:02 am

rpdom wrote:
Sat Dec 16, 2017 9:33 am
The default mount point of a drive may be hard coded, but should be able to be overridden in fstab.

You could change the default location in the webserver config. Which webserver are you using?
It's an apache2, what should I do next?

User avatar
rpdom
Posts: 12500
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: Store all website files into an external drive

Sat Dec 16, 2017 11:02 am

The file you probably want to edit is /etc/apache2/sites-enabled/000-default.conf

You will find a "DocumentRoot /var/www/html" line in there. Change the path to that of your external drive and restart apache.

Code: Select all

sudo nano /etc/apache2/sites-enabled/000-default.conf
#(edit the file and save)
sudo apachectl restart
#(you might get a warning about the ServerName here)

johndoe3226
Posts: 20
Joined: Tue Oct 03, 2017 10:37 pm

Re: Store all website files into an external drive

Sat Dec 16, 2017 11:15 am

rpdom wrote:
Sat Dec 16, 2017 11:02 am
The file you probably want to edit is /etc/apache2/sites-enabled/000-default.conf

You will find a "DocumentRoot /var/www/html" line in there. Change the path to that of your external drive and restart apache.

Code: Select all

sudo nano /etc/apache2/sites-enabled/000-default.conf
#(edit the file and save)
sudo apachectl restart
#(you might get a warning about the ServerName here)

I tried that, and I'm getting permission denied, are you sure that's all? the other tutorials I followed edited some more stuff, I'll try when I get back

User avatar
rpdom
Posts: 12500
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: Store all website files into an external drive

Sat Dec 16, 2017 11:26 am

johndoe3226 wrote:
Sat Dec 16, 2017 11:15 am
I tried that, and I'm getting permission denied, are you sure that's all? the other tutorials I followed edited some more stuff, I'll try when I get back
As you're using ntfs (any good reason not to use ext4?), you'll need to make sure that the www-data user has at least read access to that drive. ntfs doesn't understand Linux permissions, so you have to force those in /etc/fstab

johndoe3226
Posts: 20
Joined: Tue Oct 03, 2017 10:37 pm

Re: Store all website files into an external drive

Sat Dec 16, 2017 12:32 pm

rpdom wrote:
Sat Dec 16, 2017 11:26 am
johndoe3226 wrote:
Sat Dec 16, 2017 11:15 am
I tried that, and I'm getting permission denied, are you sure that's all? the other tutorials I followed edited some more stuff, I'll try when I get back
As you're using ntfs (any good reason not to use ext4?), you'll need to make sure that the www-data user has at least read access to that drive. ntfs doesn't understand Linux permissions, so you have to force those in /etc/fstab
ok, the first step is to format the drive to ext4, now I understand why the permissions had problems, was because, windows file formats don't understand permissions, silly me, I'll format and try again

User avatar
rpdom
Posts: 12500
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: Store all website files into an external drive

Sat Dec 16, 2017 12:41 pm

johndoe3226 wrote:
Sat Dec 16, 2017 12:32 pm
ok, the first step is to format the drive to ext4, now I understand why the permissions had problems, was because, windows file formats don't understand permissions, silly me, I'll format and try again
There is only one reason to format a drive using a Windows format, and that is if you need to access the contents directly by plugging it into a Windows computer.

Format as ext4 and set the owner/group of the contents as www-data and you'll be fine.

johndoe3226
Posts: 20
Joined: Tue Oct 03, 2017 10:37 pm

Re: Store all website files into an external drive

Sat Dec 16, 2017 12:52 pm

rpdom wrote:
Sat Dec 16, 2017 12:41 pm
johndoe3226 wrote:
Sat Dec 16, 2017 12:32 pm
ok, the first step is to format the drive to ext4, now I understand why the permissions had problems, was because, windows file formats don't understand permissions, silly me, I'll format and try again
There is only one reason to format a drive using a Windows format, and that is if you need to access the contents directly by plugging it into a Windows computer.

Format as ext4 and set the owner/group of the contents as www-data and you'll be fine.
Just to let you know, I followed this tutorial https://stackoverflow.com/questions/589 ... r#23175981

johndoe3226
Posts: 20
Joined: Tue Oct 03, 2017 10:37 pm

Re: Store all website files into an external drive

Sat Dec 16, 2017 1:05 pm

okay, so I formatted as ext4 and changed the DocumentRoot in /etc/apache2/sites-enabled/000-default.conf reboot and in order to set permissions I did sudo chown -a -G pi

Refresh the page, and still permission denied, so at this point the problem lies in the permissions.

Or could it be that, I should have chown something else? I don't know, please advise..

My error message on the webpage: You don't have permission to access / on this server.

johndoe3226
Posts: 20
Joined: Tue Oct 03, 2017 10:37 pm

Re: Store all website files into an external drive

Sat Dec 16, 2017 1:37 pm

and oh dear, I just realized how complicated these things can be, why can't someone develop an Apache that doesn't have these problems?

I mean having to deal with things like document roots, editing config files and sometimes even editing code !

what I want to do is nothing new or special and has been asked probably a billion times on the internet, and yet, these problems still happen.

how hard can it be? it's just changing the default directory, and this is a painful process.

Sorry if I'm ranting, I just had to voice out my opinion.

johndoe3226
Posts: 20
Joined: Tue Oct 03, 2017 10:37 pm

Re: Store all website files into an external drive

Sat Dec 16, 2017 8:12 pm

okay,so I found this on the Ubuntu site: https://help.ubuntu.com/community/Apach ... tual_Hosts

In the section virtual hosts, will that work? Assuming a totally freshly installed default configuration of a system, how exactly, step by step would you do it?

johndoe3226
Posts: 20
Joined: Tue Oct 03, 2017 10:37 pm

Re: Store all website files into an external drive

Sat Dec 16, 2017 9:49 pm

Okay, I'm super excited, I followed the ubuntu tutorial section virtual hosts and it works !

So i created a test html at /home/pi/Desktop/ and it works because of correct permissions. But, when I do the same thing at /media/pi/storage/root_folder/ it says forbidden. This is the last and final step I need to solve, but I don't know how, please help me on this last one a step-by-step would be great !


Heater
Posts: 9238
Joined: Tue Jul 17, 2012 3:02 pm

Re: Store all website files into an external drive

Mon Dec 18, 2017 12:43 am

johndoe3226,
...why can't someone develop an Apache that doesn't have these problems?
They did. Apache just works for millions of people.

Being a web server it's probably a good idea that Apache is fussy about file permissions and such. There is quite enough problems with security on the net.
Sorry if I'm ranting, I just had to voice out my opinion.
You are welcome.
Okay, nevermind, my html code was wrong
Hmmm...so it was not Apache's "fault" after all.

Return to “Networking and servers”

Who is online

Users browsing this forum: orcunbaslak and 16 guests