By default the document root folder for apache2 in Ubuntu is /var/www. This were you can store your site documents. In order to change the default site location to a different one, /opt/mysite use the following method. A detailed steps to install LAMP on ubuntu is given here.
To do this, we must create a new site and then enable it in Apache2.
To create a new site:
Copy the default website as a starting point. sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/mysite
Edit the new configuration file in a text editor “sudo nano” on the command line or “gksudo gedit”, for example: gksudo gedit /etc/apache2/sites-available/mysite
Change the DocumentRoot to point to the new location. For example, /opt/mysite
Change the Directory directive, replace <Directory /var/www/> to <Directory /opt/mysite/>
You can also set separate logs for each site. To do this, change the ErrorLog and CustomLog directives. This is optional, but handy if you have many sites
Save the file
Now, we must deactivate the old site, and activate our new one. Ubuntu provides two small utilities that take care of this: a2ensite (apache2enable site) and a2dissite (apache2disable site).
sudo a2dissite default && sudo a2ensite mysite
Finally, we restart Apache2:
sudo /etc/init.d/apache2 restart

5th Link on the 1st page of Google Search ! Congratz !
Exactly what I needed. Thx.
do you really have to create another file in sites-available? why not just use the default one and just change the directory from /var/www to /home/user/Projects/whatever/public_html?
honestly i did what i just said and it doesn’t work. gives me 403 forbidden. so i’m going to try your it you way.
you can edit the configuration file, type
sudo gedit /etc/apache2/sites-available/default
then (for instance use /home/user1 as the directory)
edit: the line that says something like:
“DocumentRoot /var/www” to
“DocumentRoot /home/user1″
then edit the line that says
“” to
“”
if you do just the first part and not the second, you will get 403 errors
I need to edit DocumentRoot valve from command line. How can I do this?
depending upon the platform you are using, use appropriate editors. For *nix platforms use vi/nano. on windows use notepad.
I need extra help with running scripts following the change of the document_root directory. I successfully changed the directory, restarted apache and tried to run a test script upon which i get the “403 forbidden: you don’t have permission to access …….. “error.
trying with default yield the desired result however. What can i do?
ensure the apache user has access to the newly created directory.
Tried a bunch of commands from different sites and now i get the error: 500 ( Internal server error).
Could you please point me to a website that gives reliable information on how to set permission to the documentroot?
Thanks.
the permissions for each files/folders should be this rw-r–r– to change to this execute sudo chmod 644 * -R under the site folder
Also internal error means there is something wrong in the config files.
Thanks dude. its work =)
Actually i fixed it with sudo chmod a+rwx
good, was gonna suggest that. a better permission is ‘sudo chmod 644′
Muchas gracias!!!
Ha funcionado perfectamente!!!
thanks a lot. really relieved me of very anxious moments being a apache newbie.
just wanted to state that all occurance of /var/www occuring in the default file have to be changed not just the first one. correct me if i am wrong.
Hi, I apache seems to need r_x permissions on the folder and files, else I get a 403 error. Just 644 didn’t work, i used “chmod 755 -R”.
Beautiful pic of the path on ur website!