Very, very new user to Ubuntu and I've been searching for a long time without finding an answer. Probably I've gotten the answer but I don't understand it all that very well so I thought I try this instead. My problem is that I don't have a permission to the var/www folder that I assume is where my "localhost" should be. I don't know how to change the permission so I can change files and add. Nether am I sure if I want to. MY intentions are only to be available to view PHP in my browser. If anyone know how I can change my permissions or how I can view PHP else way I'll be very happy.

Running Ubuntu 12.04.


P.S. As I said I'm very new so please take it slow :)


2 Answers 2


First of all, you can see the permission of /var/www has, by this command ls -l /var/www. You will see like this (this only for example):

drwxr--r--  7 www-data www-data  4096 Jun 21 10:53 CodeIgniter
drwxr--r-- 11 www-data www-data  4096 Oct  2 19:49 eAdministration

drwxr-sr-x is permission status and www-data www-data is ownership status. By default, when you installed for first time, ownership status is www-data www-data. The thing that you should do, add your username belongs to www-data group by this command:

sudo adduser yourusername www-data

After that, you should change the ownership to your username:

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

It will result in:

drwxr--r--  7 yourusername www-data  4096 Jun 21 10:53 CodeIgniter
drwxr--r-- 11 yourusername www-data  4096 Oct  2 19:49 eAdministration

Then, you should change permission to 755 (rwxr-xr-x) for directories, 644 (rw-r--r--) for files, and I do not recommend to change permission to 777 (rwxrwxrwx). As suggestion from temoto to make easier to be understand, you can do this:

sudo find /var/www -type d -print0 | sudo xargs -0 chmod u=rwX,go=rX
sudo find /var/www -type d -print0 | sudo xargs -0 chmod u=rw,go=r


sudo find /var/www -type d -print0 | sudo xargs -0 chmod 0755
sudo find /var/www -type f -print0 | sudo xargs -0 chmod 0644

To ensure that setting has been running well, you can try php code in /var/www.

  • 1
    With setting 755 recursively, all files will be set as executable. You don't want that, really.
    – gertvdijk
    Jun 24, 2013 at 21:41
  • Nowadays chmod recognise X permission as x for directories and empty for files. It's possible to run find /var/www -print0 |xargs -0 chmod u=rwX,go=rX. With added benefit of easier to understand permissions.
    – temoto
    Feb 9, 2016 at 13:33
  • ERROR, no permission for my user (that was in adduser suggested), at /var/www/html I can not do cat > test.txt even with sudo! (I used last options of sudo find etc also) Feb 13, 2017 at 20:34
  • First, could you try to find what groups are your user belongs to? Try to type groups <username>
    – metamorph
    Feb 14, 2017 at 1:12
  • There is a typo in sudo find /var/www -type d -print0 | sudo xargs -0 chmod u=rw,go=r, which will list directories (-type d) instead of files (-type f).
    – AntonK
    Jun 1, 2018 at 23:20

First of all, had you install a server as lampp? Is you did, the files sould be at some place as /opt/lampp/htdocs.

Assuming that the htdocs directory is on /var/www, you could change the permissions like this (in a Terminal, open it by searching Terminal on the Dash):

sudo chmod -R 777 /var/www
sudo chown -R **yourusername** /var/www

You must change yourusername with the username you entered in the installing process.

I hope it works to you!

  • 5
    -1 for chmoding to 777. Not necessary and also makes file appearing as executables. Hard to revert it.
    – gertvdijk
    Sep 16, 2012 at 11:49
  • As I guess you know more about Ubuntu then me, I assume I made the installation wrong. I followed a guide so I guessed it would work. Could you guide me though uninstall and reinstall? or give suggestion guide? Thanks!
    – Viktor
    Sep 16, 2012 at 16:08
  • Did you install any software for the HTTP server such as Apache, LAMPP (XAMPP) or anything like that? I think that Ubuntu Desktop hasn't any server installed by default, so if you installed something, please tell me and i'll be glad to help you. Else, if you had not installed anything, I'm sure that someone could help you to do it :) Sep 16, 2012 at 16:34

Not the answer you're looking for? Browse other questions tagged .