Krishna Karki Krishna Karki - 1 year ago 81
Linux Question

How to fix Ubuntu Forbidden issue on localhost?

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
in the browser, it says


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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download