Getting access to var/www [duplicate]

Solution 1:

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

OR

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.

Solution 2:

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!