5

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.

Thanks!

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

Viktor
  • 55

2 Answers2

9

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.

metamorph
  • 1,693
6

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!