1

Very new to Linux (Ubuntu). So getting lost each moment where this time I just installed Apache and trying to create file in www folder. But it is giving permission error.

Now I don't even know how to reach to the www folder in terminal. Embarrassing but just can't find a way.

Can anyone help me to set permission for this folder? Also how to reach to the folder in terminal.

3
  • 1
    I assume the default www folder resides in /var/www/.. May I ask; as to why are you trying to create another whilst having one in default? Also, what is the error error you're getting when trying to create & exactly are you trying to create?
    – AzkerM
    Commented Feb 19, 2014 at 13:19
  • @AzkerMohamed thanks for reply, Actually I am trying to learn Ubuntu and so Installed apache2 and php just now and trying to create inddex.php for <?php phpinfo(); ?> just to check. Now I am wonder. Is not www folder where we create a site? Commented Feb 19, 2014 at 13:22
  • You've to place it in /var/www folder where you'll see an index file.. replace an index file (or edit the current).
    – AzkerM
    Commented Feb 19, 2014 at 13:29

2 Answers 2

1

The default permission is drwxr-xr-x

The default owner is root

To reach www directory in terminal :

cd /var/www

To change permission :

sudo chmod 755 /var/www     ( this is the default)

To change the owner :

sudo chown root:root /var/www (this is the default)

To create directory in /var/www :

sudo mkdir /var/www/nameyouwant

to change the owner of the new directory :

 sudo chown username:usernamegroup /var/www/nameyouwant -R

Note you can use -R option for recursive

7
  • For the latter bit, sudo chown -R YOUR-USERNAME:YOUR-USERNAME /var/www may work better...
    – Wilf
    Commented Feb 19, 2014 at 13:24
  • Now I have big confusion after reading few docs. Where to store development files? in /var/www/ folder or in home/user/public_html/ if in public_html than I afraid I don't have that folder Commented Feb 19, 2014 at 13:29
  • in /var/www so you can access the by your browser at localhost after installing apache
    – nux
    Commented Feb 19, 2014 at 13:31
  • 1
    Okay I used @Wilf command and I am now able to create file through terminal. Just one question. DO I need to run this command every time I restart the machine? Commented Feb 19, 2014 at 13:34
  • 2
    I would not recommend taking ownership of www directory or the contents resides inside it. Instead I would advise to add the necessary user to the www-data group (which is the current group holding permission to the directory). To achieve that, user can execute sudo useradd -G www-data username
    – AzkerM
    Commented Feb 19, 2014 at 13:44
0

The default www folder used by apache lives in /var/www

However, it is owned by the apache user: www-data. To be able to place files in that folder, you can temporarily become the apache user: type sudo su www-data (within a terminal). Whatever commands you issue on that console will be done as the apache user, until you type exit

Or, even better, you can copy things over and then change them to belong to the apache user: sudo cp myfiles /var/www && sudo chown /var/www/myfiles www-data:www-data will do the trick (where myfiles are the files you want to place in the /var/www folder).

3
  • Thanks a lot for your reply. Just wonder to know in which folder I should place all site content? Sorry about very basic question but first time using Ubuntu as well as manually installing apache and php. Commented Feb 19, 2014 at 13:23
  • 2
    To downvoter: please explain why you downvote, so that I may fix the answer.
    – tucuxi
    Commented Feb 19, 2014 at 13:25
  • @pixelngrain it will work fine if you place it under /var/www. However, you can place it anywhere that the apache server will look for it. You define those things in the configuration files found in /etc/apache2/ (they are not too hard to read). For now, I would leave them in /var/www, changing permissions as needed.
    – tucuxi
    Commented Feb 19, 2014 at 13:30

You must log in to answer this question.

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