Possible Duplicate:
Whats the simplest way to edit and add files to “/var/www”?

I've just finished installing LAMP on Ubuntu and I've gone to start created a website directory and I don't know how to get into the "root" directory of LAMP.

Can I use the terminal? if so what would be the commands to create a new folder and create sub-folders inside that directory. Also save PHP, CSS files into the directory and also images.

marked as duplicate by Lekensteyn, con-f-use, John S Gruber, RobotHumans, Eliah Kagan Aug 29 '12 at 7:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    ^Possible duplicate - it's not I looked at that before posting it didn't really tell me anything, just like I searched all over google... – Will Aug 28 '12 at 19:01
  • It does explain how to open the file browser so you can put files in there. For using the terminal, see help.ubuntu.com/community/UsingTheTerminal – Lekensteyn Aug 28 '12 at 20:08
  • The question has been answered... Is this really needed to be discussed? Hell... we all need to evolve... – Geppettvs D'Constanzo Aug 28 '12 at 23:28
  • @Will If you believe this is not, in effect, the same question as that older question, please explain why in a comment. It seems to cover the same ground, so we'll probably be closing this as a duplicate of that question. (But it can be reopened, if it turns out we're wrong.) – Eliah Kagan Aug 29 '12 at 7:24

In a terminal use the next commands:

cd = Change Directory

cd /var/www

mkdir = Make Directory, this command requires elevated privileges, so run it with sudo or gksudo

sudo mkdir foldername

(where foldername is the name of the folder that you wish to create).

You can create subfolders from within /var/www without changing to the desired destination by using:

sudo mkdir foldername/subfolder

cp = Copy one or more files to another destination


This can be used for any kind of file.

Note: If you wish to use a GUI for these tasks, you can use Nautilus with elevated privileges, simply hit Alt+F2 and write gksudo nautilus, then Enter after which you will see Nautilus File Browser, press Control+L and write /var/www and you can copy/paste or drag/drop anything you wish with ease.

For a comprehensive list of the commands, visit: http://ss64.com/bash/

Good luck!


By default files under /var/www are protected. To create content under /var/www you must have root privilege.

To gain root privilege use

sudo su 

Check Apache

To make sure your apache is running fine open your browser and open http :// localhost/ . If you get a message saying "It works" Your lamp installation is successful.

Test php
Using terminal create a test php file

echo "<?php phpinfo(); ?>" | sudo tee /var/www/test.php

restart apache sudo /etc/init.d/apache2 restart

Now open http://localhost/test.php in your browser. You should get the php related configurations as output.

To create directory


eg: mkdir my_website

To copy files

cp source destination

eg: cp /tmp/test.php /var/www/my_website/

To copy whole directory

cp -r source_dir dest_dir

eg cp -r /tmp/mywebsite_content /var/www/my_website


You could do so very easily by using Nautilus, the default graphical user interface file manager of Gnome which is powering Unity in Ubuntu.

If for your own reasons would like to use the command line, the commands you should use are:

mkdir <name> example: mkdir fokis

makes a new folder named name in the current working directory.

cd <path>/ example: cd fokis/

changes the working directory to path.


shows the current working directory.

cp <file> <path> example: cp image.jpg /var/www/

copies file to path.

Not the answer you're looking for? Browse other questions tagged or ask your own question.