0

I copied a few files from a local folder to the apache server folder /var/www/html, which includes an index.html as well.

I created a test file to check php version inside the folder and it gave the correct result of phpinfo().

But I cannot run localhost/index.html from the browser. I get the error-

Forbidden

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

Apache/2.4.7 (Ubuntu) Server at localhost Port 80

I checked the owner info by running ls -l inside /var/www/html, and this is the result-

drwx--S--- 4 root www-data  4096 Mar 26 22:28 ch01
-rw-r--r-- 1 root www-data    20 Mar 26 22:16 check.php
-rw------- 1 root www-data 36911 Mar 26 22:28 fang.jpg
-rw------- 1 root www-data  2060 Mar 26 22:28 index.html
-rw-r--r-- 1 root www-data    19 Mar 26 22:28 pp.php
-rw------- 1 root www-data  1261 Mar 26 22:28 report.php
-rw------- 1 root www-data    77 Mar 26 22:28 style.css

I am trying to run the example code from head first into php and mysql.

I installed apache and php using this guide - https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu

goelakash
  • 2,502
  • 4
  • 40
  • 56
  • Try `localhost:80/index.html `..Does the index page show up? – Lal Mar 26 '15 at 17:08
  • Is your server launched by root? Else you should either make file readable for all, or make Apache user own them. Or at least readable for the www-data group. – Michael Laffargue Mar 26 '15 at 17:10
  • Your apache user is probably www-data; `check.php` can be read by www-data, `index.html` can't. – nlu Mar 26 '15 at 17:11
  • The check.php and index.html permissions seem to be different. It looks like a permission issue on the file to me. – Hozikimaru Mar 26 '15 at 17:11
  • probably better at super user,, or maybe server fault.. but `chmod 644 index.html` as the web server cannot read them. Also the apache error logs helps – Doon Mar 26 '15 at 17:11
  • See if this [link](http://stackoverflow.com/a/14671738/3168859) helps you.. – Lal Mar 26 '15 at 17:12
  • @MichaelLaffargue I launch apache with "sudo service apache2 reload" command from terminal. – goelakash Mar 26 '15 at 17:12
  • @goelakash `reload` won't change the process owner if it's not yet root. You should just make the files and directory accessibles from the normal "apache user" – Michael Laffargue Mar 26 '15 at 17:14
  • Server has to be launched as root (to bind to port 80). But by default it will setuid itself to a non privileged user before it starts to server content – Doon Mar 26 '15 at 17:16

2 Answers2

0
-rw------- 1 root www-data  2060 Mar 26 22:28 index.html

The file is

  • owned by root (who can read and write to it (rw-))
  • a member of the www-data group (which can't do anything with it (---))
  • can't be touched by the public (---)

Your webserver is almost certainly running as www-data, so you need to either:

  • Change the ownership of the file: chown www-data index.html or
  • Give the group permission to edit it: chmod 660 index.html

You have similar issues with other files.


NB: The current ownership and permissions suggests that you are using the root account to manage the files for the website. Don't do that. Create an account with more limited access for that purposes. Only run as root when you really have to.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • But only the root can access the /var/www/html folder. Do I change the default folder for the server then? – goelakash Mar 26 '15 at 17:21
  • @goelakash — No. Change who can access it. e.g. by creating an account that is a member of the `www-data` group and making the directory accessible to members of that group. – Quentin Mar 26 '15 at 17:21
  • I did a "chmod 644 -R * " for all the files in the folder and its working. Do I have to change the user now? – goelakash Mar 26 '15 at 17:30
-1

the default location is

/var/www/

and not '

/var/www/html/

you can access the index.html at

http://localhost:80/html/index.html
Rex Adrivan
  • 993
  • 1
  • 10
  • 23