Apache Alias not working in .htaccess - apache

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

Related

Apache2 relative paths not working

Good Morning,
I am currently setting up and apache2 server on my raspberry pi. My index.html file is in the directory /var/www/html and the file is loading fine when I go to the IP address. However, the images located in /var/www/html/img are not loading. The html is like this: <img alt="image1" src="img/picture1.png">. When I right click on the alternative image icon, and select open image in new tab, I get:
You don't have permission to access /img/picture1.png on this server.
Server unable to read htaccess file, denying access to be safe
How can I prevent this and make the user able to access the image?
Many thanks,
Try
chmod -R 755 /img/
this will set the permission for all files in the folder readable and executable for all, and also writable by the owner.
The output will be in the form
-rwxr-xr-x 1 root root 0 Apr 5 12:38 picture1.jpg

Apache can't serve DocumentRoot : no execute permission error

I am trying to migrate a web application from a Slackware config of Apache to a CentOS 7 one. DocumentRoot set to /home/STORAGE and there is a simple index.html file in it for testing. Both /home/STORAGE and index.html have 777 permissions set, yet Apache reports :
access to /index.html denied ... because search permissions are missing on a component of the path.
On the other hand, phpMyAdmin works fine, configured with a separate .conf file in /etc/httpd/conf.d . I tried using their example to make a .conf file for my app, but it still reports the same error. I don't even know where to start looking here.
EDIT:
I think this has something to do with the user of Apache. It is set to a local user in httpd.conf not to root, but the only pages the server serves are those in directories owned by root.
It was not a permission error but a Selinux issue. I decided to use the default /var/www/html for the application but still, had to allow write access to some dirs. Here is what I typed:
sudo chcon -t httpd_sys_rw_content_t /some/dir/in/var/www/html -R
The first time I typed it without -R and the permissions didn't change (check with ls -Z /dir/path). Now it is fine.

Apache 403 on certain folders

I'm running dev server on Centos 6.4 with Apache 2.2. I just moved a site from the production to dev to perform upgrades. I modified file owner to apache:apache (httpd user) and set all directories to 755 and files to 644. I have few other sites in the DocumentRoot folder with similar settings and they run fine (using same CMS, PHP, MySQL versions etc).
I have no virtual hosts defined and Allow all on everything. httpd.conf is default.
I'm not able to make site working from the folder I just moved from the production. I'm getting 403 every time.
As suggested in
https://serverfault.com/questions/272947/apache-on-centos-5-6-gives-me-permissions-denied-error/272956#272956
Usually that comes from Selinux not giving access to the folder. do
ls -alZ /var/www
and if the html folder doesn't have the context system_u:object_r:httpd_sys_content_t, fix it with chcon
chcon -v -R --type=httpd_sys_content_t /var/www/html
http://wiki.centos.org/HowTos/SELinux

Amazon EC2 How Do I host My Own Content? Stuck on having a working test apache page

I am using this guide:
http://codingthis.com/platforms/linux/how-to-host-simple-content-with-amazon-elastic-cloud-computing-ec2/
I have a folder named public_html in my /home/ec2-user directory with a test.html file.
What I have done so far:
sudo yum -y install httpd php
sudo chkconfig httpd on
chmod 755 /home/ec2-user (I HAVE NO IDEA WHAT THIS DOES)
sudo nano /etc/httpd/conf/httpd.conf
(changed DocumentRoot to DocumentRoot /home/ec2-user/public_html)
TLDR: How do I make it load my content (my html file) instead of the apache test page
EXTRA:
I have a security group enabled for my instance with rules:
ICMP Allow ALL
TCP Allow ALL
UDP Allow ALL
TCP port 80 (Http)
isnt your document root public_html instead of www? so why did u put ur pages under www directory?
If you have no content in the DocumentRoot that you configured then the default Apache install will show you that page instead of yours. Also, check the DirectoryIndex configuration to make sure that if you're using index.php or default.html or something else that this is configured as well. It defaults to index.html
Chmod755/directory/directory/etc.. Will give access to that directory. So if your website is in the folder *home/ec2-user/public_html* you would then need to give access to that directory.
Example: chmod 755 home/ec2-user/public_html
I was having the same issue. I fixed it by changing the permissions on the ec2-user directory like so:
chmod +x home/ec2-user
This give execution permissions to everyone on your user directory.
I had the same problem. All I have to do was just restarting the ec2 to apply the changes. - takes me 2h :(

How to setup FollowSymLinks?

I am trying to have Apache follow a symlink to a raid array server that will contain some large data files. I have tried modifying httpd.conf to have an entry like this
<Directory "/Users/imagine/Sites">
Options FollowSymLinks
AllowOverride all
Order allow,deny
Allow from all
</Directory>
to have Apache follow any sym link in the Sites folder.
I keep getting an error return that seems to indicate I don't have any permissions to access the files. The error is:
Forbidden
You don't have permission to access
/~imagine/imageLibraryTest/videoClips/imageLibraryVideos/imageLibraryVideos/Data13/0002RT-1.mov
on this server.
The sys link file is the last "imageLibraryVideos" in the line with the Data13 being the sub dir on the server containing the file.
The 0002RT-1.mov file hase these permissions:
-rwxrwxrwx 1 imagine staff 1138757 Sep 15 17:01 0002RT-1.mov
and is in this path:
cd /Volumes/ImagineProducts-1/Users/imagine/Sites/imageLibraryVideos/Data13
the link points to:
lrwxr-xr-x 1 imagine staff 65 Sep 15 16:40 imageLibraryVideos -> /Volumes/ImagineProducts-1/Users/imagine/Sites/imageLibraryVideos
I had the same problem last week and the solution was pretty simple for me.
Run:
sudo -i -u www-data
And then try navigating the path, directory by directory. You will notice at some point that you don't have access to open the dir.
If you get into the last directory, check that you can read the file (with head for example).
Look in the enclosing directories. They need to be at least mode 711. (drwx--x--x)
Also, look in /var/log/apache2/error_log (Or whatever the concatenation of ServerRoot and ErrorLog is from the httpd.conf) for a possibly more-detailed error message.
Finally, ensure you restart apache after messing with httpd.conf.
You should also look at bind mounts rather than symlinks - that would allow you to remount a given path at a new point. The following is an example:
mount --rbind /path/to/current/location/somewhere/else /new/mount/point
You can also edit your fstab to do this at boot:
/path/to/original /new/path bind defaults,bind 0 0
This is a permissions problem where the user that your web server is running under does not have read and/or execute permissions to the necessary directories in the symbolic link path. The quick and easy way to check is to su - web-user (where web-user is the user account that the web server is running under) and then try to cd into the path and view the file. When you come across a directory that you don't have permission to enter, you'll have to change the permissions and/or ownership to make it accessible by the web server user account.