Skip to main content Skip to navigation

Why aren't my web pages being served?

If you have put web pages in /var/www/html/ and find they are not being served, this could be due to file system permissions and/or SELinux types.

Quick fix

You can set the correct file permissions by running

$ find /var/www/html/ -type f -exec chmod a+r {} \;
$ find /var/www/html/ -type d -exec chmod a+rx {} \;

The first command adds user/group/global read permission on all files in /var/www/html/. The second adds user/group/global execute permission on all directories in /var/www/html/

If you find your web pages are still not being served, you can set the correct SELinux type by running

$ restorecon -r /var/www/html/

More Information

When permissions and SELinux type should automatically be set correctly

If you create files in /var/www/html/ then permissions and SELinux type should be set correctly.

[admin@foo-test ~]$ cd /var/www/html/
[admin@foo-test html]$ mkdir foo
[admin@foo-test html]$ echo "hello, this is foo" > foo/index.html
[admin@foo-test html]$ ls -ldZ foo
drwxrwsr-x. admin admin unconfined_u:object_r:httpd_sys_content_t:s0 foo
[admin@foo-test html]$ ls -ldZ foo/index.html 
-rw-rw-r--. admin admin unconfined_u:object_r:httpd_sys_content_t:s0 foo/index.html
[admin@foo-test html]$ 

You can see that foo has global execute permission , the SELinux type of both foo and index.html is httpd_sys_content_t and things work as expected

bob@bobhost:~>curl http://foo-test.lnx.warwick.ac.uk/foo/
hello, this is foo
bob@bobhost:~>

Similarly, if you create files in admin's home directory then copy them to /var/ww/html

[admin@foo-test html]$ cd
[admin@foo-test ~]$ pwd
/home/admin
[admin@foo-test ~]$ mkdir baz
[admin@foo-test ~]$ echo "hello, this is baz" > baz/index.html
[admin@foo-test ~]$ ls -ldZ baz/
drwxrwxr-x. admin admin unconfined_u:object_r:user_home_t:s0 baz/
[admin@foo-test ~]$ ls -lZ baz/index.html 
-rw-rw-r--. admin admin unconfined_u:object_r:user_home_t:s0 baz/index.html
[admin@foo-test~]$ cp -r baz /var/www/html/
[admin@foo-test ~]$ ls -ldZ /var/www/html/baz/
drwxrwsr-x. admin admin unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/baz/
[admin@foo-test ~]$ ls -lZ /var/www/html/baz/index.html 
-rw-rw-r--. admin admin unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/baz/index.html
[admin@foo-test ~]$ 
bob@bobhost:~>curl http://foo-test.lnx.warwick.ac.uk/baz/
hello, this is baz
bob@bobhost:~>
When permissions and SELinux type won't automatically get set correctly

If you create files in admin's home directory then move (rather than copy) them to /var/www/html/

[admin@foo-test html]$ cd
[admin@foo-test ~]$ pwd
/home/admin
[admin@foo-test ~]$ mkdir bar
[admin@foo-test ~]$ echo "hello, this is bar" > bar/index.html
[admin@foo-test ~]$ ls -ldZ bar/
drwxrwxr-x. admin admin unconfined_u:object_r:user_home_t:s0 bar/
[admin@foo-test ~]$ ls -ldZ bar/index.html 
-rw-rw-r--. admin admin unconfined_u:object_r:user_home_t:s0 bar/index.html
[admin@foo-test ~]$ mv bar /var/www/html/
[admin@foo-test ~]$ ls -ldZ /var/www/html/bar/
drwxrwsr-x. admin admin unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/bar/
[admin@foo-test ~]$ ls -ldZ /var/www/html/bar/index.html 
-rw-rw-r--. admin admin unconfined_u:object_r:user_home_t:s0 /var/www/html/bar/index.html
[admin@foo-test ~]$ 

Permissions are correct, but the SELinux type is wrong so index.html won't be served.

bob@bobhost:~>curl http://foo-test.lnx.warwick.ac.uk/bar/
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /bar/index.html
on this server.</p>
</body></html>
bob@bobhost:~>
[admin@foo-test ~]$ restorecon -r /var/www/html/
[admin@foo-test ~]$ ls -lZ /var/www/html/bar/index.html 
-rw-rw-r--. admin admin unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/bar/index.html
[admin@foo-test ~]$ 
bob@bobhost:~>curl http://foo-test.lnx.warwick.ac.uk/bar/
hello, this is bar
bob@bobhost:~>


If you create files on a different machine, then copy them over to admin's home directory on the server then move them to /var/www/html/

bob@bobhost:~>cd /tmp/
bob@bobhost:tmp>mkdir blah
bob@bobhost:tmp>echo "hello this is blah" > blah/index.html
bob@bobhost:tmp>ls -ld blah/
drwx------. 2 bob bob 60 Dec  6 11:43 blah/
bob@bobhost:tmp>ls -ld blah/index.html 
-rw-------. 1 bob bob 19 Dec  6 11:43 blah/index.html
bob@bobhost:tmp>scp -r blah admin@foo-test.lnx.warwick.ac.uk:
admin@foo-test.lnx.warwick.ac.uk's password: 
index.html                                                                                                                                                                                                  100%   19     0.0KB/s   00:00    
bob@bobhost:tmp>ssh admin@foo-test.lnx.warwick.ac.uk
admin@foo-test.lnx.warwick.ac.uk's password: 
Last login: Tue Dec  6 10:21:42 2016 from crash.csv.warwick.ac.uk
[admin@foo-test ~]$ ls -ldZ blah/
drwx------. admin admin unconfined_u:object_r:user_home_t:s0 blah/
[admin@foo-test ~]$ ls -ldZ blah/index.html 
-rw-------. admin admin unconfined_u:object_r:user_home_t:s0 blah/index.html
[admin@foo-test ~]$ cp -r blah /var/www/html/
[admin@foo-test ~]$ ls -lZ /var/www/html/blah/index.html 
-rw-------. admin admin unconfined_u:object_r:user_home_t:s0 /var/www/html/blah/index.html
[admin@foo-test ~]$ ls -ldZ /var/www/html/blah/
drwx------. admin admin unconfined_u:object_r:user_home_t:s0 /var/www/html/blah/

Both permissions and SELinux type are wrong so index.html isn't served.

bob@bobhost:~>curl http://foo-test.lnx.warwick.ac.uk/blah/
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /blah/index.html
on this server.</p>
</body></html>
bob@bobhost:~>
[admin@foo-test ~]$ find /var/www/html/ -type f -exec chmod a+r {} \;
[admin@foo-test ~]$ find /var/www/html/ -type d -exec chmod a+rx {} \;
[admin@foo-test~]$ ls -ldZ /var/www/html/blah/
drwxr-xr-x. admin admin unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/blah/
[admin@foo-test ~]$ ls -lZ /var/www/html/blah/index.html 
-rw-r--r--. admin admin unconfined_u:object_r:user_home_t:s0 /var/www/html/blah/index.html
[admin@foo-test ~]$ restorecon -r /var/www/html/
[admin@foo-test ~]$ ls -lZ /var/www/html/blah/index.html 
-rw-r--r--. admin admin unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/blah/index.html
[admin@foo-test ~]$ 
bob@bobhost:~>curl http://foo-test.lnx.warwick.ac.uk/blah/
hello this is blah
bob@bobhost:~>