Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

This question already has an answer here:

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?

share|improve this question
add comment

marked as duplicate by Michael Hampton Jun 9 '13 at 23:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

up vote 2 down vote accepted

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
share|improve this answer
    
Thanks for your answer. I did typed setenforce 0 but now I'm getting error 500 and apache log file says: Premature end of script headers –  faridv Jun 9 '13 at 20:06
    
@faridv: You have other problems too. –  Iain Jun 9 '13 at 20:13
    
Line what? I just created a new partition, mounted it to /data/ and then copied media folder from /home to here. What should I do? It's a production website and now I'm stuck in a bad situation! –  faridv Jun 9 '13 at 20:15
    
When I type ls -Z in /data/ folder I get drwxrwxrwx. apache apache unconfined_u:object_r:file_t:s0 media. I have no idea what does it mean. Can it help me finding the problem? –  faridv Jun 9 '13 at 20:18
1  
@faridv: You have 2 problems. The first Symbolic link not allowed or link target not accessible: /var/www/html/media appears to be caused by SELinux and I've provided an answer to that question. The second Premature end of script headers is an entirely different problem and it's resolution is much more difficult to diagnose remotely and is more likely an application/programming error. –  Iain Jun 9 '13 at 20:23
show 6 more comments

Not the answer you're looking for? Browse other questions tagged or ask your own question.