Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to copy a file from my server to my desktop computer. I placed it in /var/www/html (where the web pages are) and when I try to download it I get 403 Forbidden. I even tried chmod 777 on the file and it doesn't fix it.

What am I doing wrong and why am I getting this error?

share|improve this question
up vote 8 down vote accepted

You need to modify the file so that it is owned by the Apache user. By default, Apache will run as the www-data user (found in the www-data group). You can use chown to modify the file's owner (may have to be used with sudo):

chown -R www-data:www-data /var/www/html

Finally, you need to ensure the files have at least read and execute permissions for the Apache user. You've already done this, as you said, but after modifying all the permissions/file owners, you should ensure everything's okay by running ls -l /var/www/html. As a security measure, it's also wise to remove all permissions for other users:

chmod -R 0550 /var/www/html

Note that if you use PHP or another scripting language which requires write access, you may have to modify the permission mask above to 0770 instead. As a precaution, only use that mask on directories where required (e.g. to write website cache data, or upload files)

share|improve this answer
chown: 'www-data:www-data' invalid user – ioSamurai May 9 '12 at 22:49
also tried apache as the user and it didn't give an error but I still can't download the file (403) – ioSamurai May 9 '12 at 22:52
@Ryan you need to check your httpd.conf or apache2.conf files to see what the actual Apache username is. – Breakthrough May 10 '12 at 4:31
Ok, will do. Is it also possible that the file types have different permissions too? Because I can browse rich html pages with images and such on the same paths. – ioSamurai May 10 '12 at 13:29
@Ryan check using ls -l who owns those files, and what permissions they have. Are you attempting to access a raw HTML file, or some kind of dynamic page (i.e. PHP/Python/Ruby)? Also, make sure you didn't set any kind of blocking rules in your .htaccess, httpd.conf, or site configuration files. – Breakthrough May 10 '12 at 16:46

You probably have SELinux enabled. Simplest way around it for the current purpose is to chown the file in question to the user ID Apache is running as.

share|improve this answer

I'm using CentOS 7 + Apache, the only command that resolved my issue is it (because I tried chown+chmod before):

sudo setenforce 0 #disable SELinux

And then, I can download the file (in my case,, but, it can open the doors for attackers write and execute code.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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