0

I have a VPS with CentOS and I'm facing a very strange behavior by Apache webserver.
I started this server with 50GB of disk space and soon I ran out of space so I asked maintenance department and they added another 50GB as a new hard drive. So I created a new partition and mounted it in /home/media and I moved all my website media files to this place and at the end I created an SymLink like this:

lrwxrwxrwx.  1 apache apache    12 May 15 14:07 media -> /home/media/

Today, I ran out of disk space once more and they did added a new hard drive with 100GB capacity this time. I just wanted to do the same as I did for /home/media/ but this time it's called /data/media.

lrwxrwxrwx.  1 apache pooya    12 Jun  9 22:43 media -> /data/media/

Now when I navigate to files in media folder in browser, I get Forbidden 403 error.

I checked Apache's error log and it says: Symbolic link not allowed or link target not accessible: /var/www/html/media.

All the solutions for this error on Internet is to add Options Indexes FollowSymLinks or webserver facing access problems with symliked directory.

I have the FollowSymLinks in both apache config file and my root .htaccess file. All the files and folders and also their parents in /data/media/ are chmodded to 777 and the chown of them is apache:apache.

What is wrong with my webserver?

Farid Rn
  • 205

1 Answers1

2

You should almost never need to have 777 permissions in your web tree.

You probably need to fix the SELinux permissions since /data/media isn't a standard location to store web files. You can quickly test this by temporarily disabling SELinux

setenforce 0

Run some tests and if the web files are now accessible SELinux is to blame. Reenable Linux

setenforce 1

then fix the problem

semanage fcontext -a -t httpd_sys_content_t "/data/media(/.*)?"

followed by

restorecon -r -v /data/media

Now apache should be able to access the files.


The semanage utility is provided by the policycoreutils-python package so you can install it with

yum install policycoreutils-python
user9517
  • 117,122