2

How the website was created:

The website's files were copied from another machine as a compressed folder:

WEBSITE.tar.gz

I decompressed and moved the content to /var/html/www in the new webserver, and that gives as result that the files are for example located as follows:

/var/html/www/index.html
/var/html/www/css/styles.css
/var/html/www/img/photo.jpeg

The permissions of the files and directories resulted different than they were in the previous machine, so I researched and found this solution to quickly fix the permissions:

sudo chmod -R u+rwX,go+rX,go-w /var/www/html/*

I checked the permissions of the files and now they did show the way I expected:

cd /var/www/html
ls -a -l
drwxr-xr-x. 2 root root size month day hour css
drwxr-xr-x. 2 root root size month day hour img
-rw-r--r--. 1 root root size month day hour index.html

cd /var/www/html/img
ls -a -l
-rw-r--r--. 1 root root size month day hour photo.jpeg

cd /var/www/html/css
ls -a -l
-rw-r--r--. 1 root root size month day hour styles.css

The problem:

I still get this message when trying to access a page of the website:

Forbidden You don't have permission to access /index.html on this server

Then I did an experiment:

sudo mv index.html index.html.backup
sudo cp index.html.backup index.html

And the page loaded normally now, but wouldn't show the image and the styles. So if I complete the process of copying I will get the image and the styles to show in the website:

sudo mv css css.backup
sudo cp css.backup css
sudo mv img img.backup
sudo cp img.backup img

It worked, but what's the explanation? I don't want to look past the mystery, I want to know what's the "normal" way to solve the problem, other than copying the files.

  • Is it a Mac or what distro of linux? – Rui F Ribeiro Jun 15 '17 at 23:34
3

For GNU-coreutils ls including on Linux, dot at the end of modebits means SELinux 'context' applies -- use ls [-l] -Z (or --context) to see details -- and (recent) RedHat/CentOS by default enables SELinux to restrict access to all kinds of resources including files.

Unless you want to use SELinux features to control access, the simple way to mostly ignore it is [sudo] restorecon [-R] on the files, see man restorecon; and the ways to disable SELinux are given at man setenforce

Related question What does a dot after the file permission bits mean?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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