Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can't access anything inside of localhost, whenever I try to access anything inside of localhost it gives me 403 Forbidden error. I also can't add any files into the var/www/ folder unless I open it through sudo; Nonetheless, when I access localhost itself the default html appears which says it works. What could be causing this to happen? Thanks.

share|improve this question
up vote 1 down vote accepted

Well, for security reasons, /var/www folder is usually only accessed via sudo. If you wish to drop your files, let's say: your index.html, images folder and other stuff inside of it you will be in the need to start nautilus (or your preferred files browser) with elevated privileges by running sudo nautilus in a terminal or gksudo nautilus in the "Run application" dialog window, this will cause the /var/www to be accessed with both read and write access.

enter image description here

Related to your "403 Forbidden error" you must be sure that the files inside of /var/www have the right permissions, which can be changed via sudo chmod 755 /var/www -R in a terminal for read/write permission only for the owner and read and execute permissions for users and others.

However, if we wish to use another local folder for testing in our website/HTML/PHP code, we can change the default folder location used by our localhost/php engine to manage these files. This is done using the following procedure:

  1. sudo gedit /etc/apache2/sites-available/default
  2. Provide user password

Then, change all occurrences of "/var/www/" to the folder that we use to test our site/HTML/PHP. (Example: /home/geppettvs/www/ or where appropriate, change "geppettvs" with your local folder.

After that you must restart the computer for the purpose of the changes to take effect. Do not forget also that the files must have the proper file permissions to run properly. (755 is usually sufficient, but some folders [and/or files] may need 777 permissions to read and write them correctly.)

Another trick would be to stop/restart the Apache service but I prefer to restart the computer. In addition, you might need to clear your cache/browsing history in order to the changes take effect and stop receiving the It works! from the sample page.

Good luck!

Parts of this answers comes from:

share|improve this answer

Please write to terminal: "gksu nautuilus" (without quotes) write your (if you're admin) password to pup up window.Navigate to /var/ on your file system. Right click on "www" directory and go to properties->permissions and set your user account to owner. Sorry for the terrible English.

Update #1 While writing the message I'm sorry I did not notice that you have answered.

share|improve this answer

Go to sudo vim /etc/apache2/sites-available/default and change DocumentRoot e.g. DocumentRoot /home/your-name/www

[2] sudo /etc/init.d/apache2 restart

share|improve this answer
Thanks this was useful :), can't upvote due to low reputation though. – fenerlitk May 4 '12 at 21:07
A good thing is to move your mysql file to /home folder too. When you install a new version of OS, the home folder stays untouched – Fero May 4 '12 at 22:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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