How to fix Ubuntu Forbidden issue on localhost?

12,965

The /var/www folder needs to be readable by the www-data system account. Try this :

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

Edit : as noted by Joachim Isaksson, that was a quick fix to the problem. A more secure way of setting up the permissions would look like :

sudo chown -R krishna:www-data /var/www
sudo chmod -R 755 /var/www

You might need to give write access to www-data at some point though, for example to enable file uploads to your server. It's best if you can keep this to a dedicated directory in your website tree.

Share:
12,965
Krishna Karki
Author by

Krishna Karki

Web Developer

Updated on June 18, 2022

Comments

  • Krishna Karki
    Krishna Karki almost 2 years

    I have installed Lamp and phpmyadmin in Ubuntu running on my computer. This is my Ls- L result on terminal.

    drwxr-xr-x  2 root    root     4096 Jul  3 12:30 backups
    drwxr-xr-x 19 root    root     4096 Jul  3 13:37 cache
    drwxrwsrwt  2 root    whoopsie 4096 Jul  3 12:30 crash
    drwxr-xr-x  2 root    root     4096 Feb 14 03:55 games
    drwxr-xr-x 61 root    root     4096 Jul  3 13:37 lib
    drwxrwsr-x  2 root    staff    4096 Apr 19  2012 local
    lrwxrwxrwx  1 root    root        9 Jul  3 15:50 lock -> /run/lock
    drwxr-xr-x 18 root    root     4096 Jul  3 16:56 log
    drwxrwsr-x  2 root    mail     4096 Feb 14 03:52 mail
    drwxr-xr-x  2 root    root     4096 Feb 14 03:52 opt
    lrwxrwxrwx  1 root    root        4 Jul  3 15:50 run -> /run
    drwxr-xr-x  8 root    root     4096 Feb 14 03:53 spool
    drwxrwxrwt  2 root    root     4096 Jul  3 17:16 tmp
    drwxr-x--x  3 krishna root     4096 Jul  3 15:11 www
    

    When I enter http://localhost/ in the browser, it says

    Forbidden

    You don't have permission to access /index.html on this server. Apache/2.2.22 (Ubuntu) Server at localhost Port 80.
    I am able to create files and folders in var/www folder but I'm unable to execute it from the browser.
    How to fix this issue, please, suggest me? I am new to Ubuntu.

  • fedorqui
    fedorqui almost 11 years
    chmod -R 755 /var/www should be enough.
  • Krishna Karki
    Krishna Karki almost 11 years
    it says krishna@krishna:/var$ sudo chown -R www:root /var/www [sudo] password for krishna: chown: invalid user: www:root' krishna@krishna:/var$ `
  • Miklos Aubert
    Miklos Aubert almost 11 years
    Yes, my mistake, it's actually www-data on Ubuntu.
  • Joachim Isaksson
    Joachim Isaksson almost 11 years
    Good thing that it solved the problem. That said, I think www-data should probably not be owner of the directory with 755 permissions, that means the web server can write to the web root and replace all your scripts. To me, having someone else own the directory and giving group read permission for the group www-data feels safer.