I have installed Apache 2.4 on Ubuntu 16, all works.
I have a website sitting on localhost, this also works fine.
I need to be able to access files on a USB drive to use within the website.
I'm using PHP to access the USB drive and obtain information of files, this works fine, however the issue arises when I try to display an image on the web page.
I'm using the .htaccess file and trying to use mod_alias to add a folder on the USB drive into the website, here is the content on my .htaccess file
DirectoryIndex index.php
Alias "/USB" "/mnt/sdb1/images"
<Directory "mnt/sdb1/images">
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
AddType audio/mpeg .mp3
So I know the .htaccess file is working because it loads my index.php file as the main file when I go to LocalHost.
I know the file path of the USB drive is correct because the PHP script has accessed it and collected the image files to display on the page, so PHP uses scandir to get all of the images in a folder (/mnt/sdb1/images) and it echos to the page correctly to show the images, for example;
<img src="/USB/image1.jpg" />
But the images aren't loading on the page itself and I presume it's because the Alias doesn't appear to be working.
Please help.
One possibility is that you need to grant www-data access to the USB files. Usually in Apache directories, you set the owner to something like:
chown root:www-data *
chmod 750 * (for directories)
chmod 640 * (for files)
But, you may not be able to do that on a USB drive (sorry, never dealt with USB), but if it is a particular group, you could add www-data to that group:
sudo usermod -a -G <USBGroup> www-data
So, for example, I have a shared drive on my Virtual Machine (/media/sf_node), which I am guessing works a lot like a USB drive. So when I run the following command:
ls -la /media/sf_node
I see:
drwxrwx--- 1 root vboxsf 4096 Jan 27 11:10 web
That shows the group vboxsf for that directory. Then I can do a:
usermod -a -G vboxsf www-data