Domanda

I have tried looking for an answer all across Google and here but none have helped thus far..

I have a raspberry pi with raspbian (debian) for an OS that has an external hard drive attached to it via USB. I have mounted it and share it through my network. The drive is mounted to be "/media/Backup". I can access files and folders on the drive without any issues from both the server side and on any computer on the network.

I am also trying to host a webserver that will display the first 2 levels of directories that are on the hard drive. If I use this code below in a PHP file:

$dir    = '/media';
$files1 = scandir($dir);
print_r($files1);

the results are:

.
..
Backup

So far, everything works fine.. Now onto the problem. If I try to use this code:

$dir    = '/media/Backup';
$files1 = scandir($dir);
print_r($files1);

it will result in no files/folders found.

I am unsure if this is a problem within PHP or within Debian in the way the drive is accessed.

I am tagging this under both categories since I am unsure of what the problem is.

Any help is greatly appreciated.

Perhaps something is wrong with my Apache access level for the drives?

È stato utile?

Soluzione

Well it turns out that I did meed to add permission for user "www-data" to have access to my external drives. For future people who have this problem, here is what I did.

I first created a directory (which will represent the drive once done mounting) using:

sudo mkdir /media/HD2

Once the directory is made then you can now mount the drive to it:

sudo mount /dev/sdb1 /media/HD2

where /dev/sdb1 is my drive.

Next I add an entry to fstab for the drive:

sudo nano /etc/fstab

I add another entry to the file like this:

/dev/sdb1    /media/HD2    vfat    permissions,defaults,auto    0    0

Use vfat for fat32 file systems and ntfs if the drive is that. Don't use any spaces;use tabs.

Save fstab. Lastly run this:

sudo chown -R www-data:www-data /media/HD2

This allows all files and folders inside HD2 to be accessed by the user www-data which includes apache.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top