By default the document root folder for apache2 in Ubuntu is /var/www. This is where 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 (make sure there is no space in your new folder name; /opt/my\ site/ will not work)
Change DocumentRoot /var/www to DocumentRoot /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 service apache2 restart

Error: cannot effectuate ‘stat’ on «/etc/apache2/sites-available/default»: No such file or directory
I’ve browse to that folder and there’s two files, one called 000-default and another one called 000-default-config or something like that. Any ideas?
Hi,
I tried it and does not work for me.
I continue to get the message 403 Forbidden.
Any help will be appreciated.
Thanks,
Valerius
Hi, using Linux Mint 13 and stuck with this:
ERROR: Site mysite does not exist!
Kindly help.
Thanks.
Worked for me. Thanks.
Hi guys,
Can you please tell me how to enable multiple virtual host in localhost(Ubuntu)
I want three localhost similar directories with 3 different root path.
Can you suggest where to change it..
I was getting same forbidden error (In windows machine for wamp), after lot of r & d I found that there is need to change default virtual host in httpd-vhosts.conf file which is present in C:\wamp\bin\apache\Apache2.2.17\conf\extra
From :
ServerAdmin webmaster@localhost
DocumentRoot “c:/wamp/www”
ServerName localhost
ErrorLog “logs/localhost-error.log”
CustomLog “logs/localhost-access.log” common
To:
ServerAdmin webmaster@localhost
DocumentRoot “E:/wamp/www”
ServerName localhost
ErrorLog “logs/localhost-error.log”
CustomLog “logs/localhost-access.log” common
Hope linux will need same change to accomplish this
Thanks
Oh !! Thanks so much !! This is what i need !
Sorry. I’m come from Viet Nam and rather poor english.
If you still have problems with 403 error , you should try this:
open with your favourite editor as a sudo this file: /etc/apache2/httpd.conf
By default it should be a blank file. Now in this file add this line: User
it’s the user with which you are loged in on your machine.
why i can change the default to phpmyadmin..??
solved !!! 😀
done by changing the user that apache is running from www-data to your own account.
paste the following lines in your httpd.conf file:
IfModule !mpm_netware_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User ###PUT_YOUR_USERNAME_HERE###
Group ###PUT_YOUR_GROUPNAME_HERE###
Thanks man, that really works!!!
Yes! Finally got it working after doing this as well.
This is the only solution work for me.
Thank you
You are welcome Moses.
I am still getting the 403 forbiddon error..tried with all the set of permissions mentioned in the blog…
what did i do:
editd the default file in avialable-sites to point to some folder in my home directory
and then change the permissions…
I need to get this done at the earliest..
HELP ME PLEASE !!!
Nevermind my previous post. I followed your instructions. Worked Great! THANKS!!
I changed the line in sites-available/default to my new directory. Saved and restarted apache. Worked great. Problem is that default.conf reverts back to “DocumentRoot /var/www” everytime I restart/ reboot the machine. How do I prevent this?
Thanks for the good documentations, but my problem was not solved here, I had solved it. Thanks
Thanks man! It’s exactly what I’m looking for!
i did this and got the above error,any help?
nuaha@nuaha-Satellite-C660:~$ sudo service apache2 restart
* Restarting web server apache2 Warning: DocumentRoot [/nuaha/mysite] does not exist
… waiting Warning: DocumentRoot [/nuaha/mysite] does not exist
[ OK ]
nuaha@nuaha-Satellite-C660:~$ gksudo gedit /etc/apache2/sites-available/mysite
nuaha@nuaha-Satellite-C660:~$ sudo service apache2 restart
* Restarting web server apache2 Warning: DocumentRoot [/nuaha/mysite] does not exist
… waiting Warning: DocumentRoot [/nuaha/mysite] does not exist
[ OK ]
Ajo Paul, I commend you for your effort to help others (myself included) and hope that you don’t get discouraged by someone like v…
Thank you Jim.
It was nice documentation, but my problem is not yet solved, my folder is in /home/user/folder and now how i should give this paths to the /etc/apache2/site-availble/mysite
I have give like this : DocumentRoot “” and <Directory "
so when I restart the apache it said that these path is wrong. would you please help me. Thanks in advance
Alright, will try again. What is your apache version OS?
Thank you ! exactly what i needed.
You are welcome.
Your last step is the old way of restarting apache2
latest is “service apache2 restart” …..
Thanks will update the same.
GET A JOB !!! :…
default wp template … u didn’t even changed the basic layout …. neither the basic image …. or the basic menu ……..and in addition the proposed configuration is ….. i’d better not say… dunno how u got on the top but i hope ppl will realize ho useless this site is and how useless solutions u purpose.
Please consider to close the site and to go to working in a cotton field.
U only made me loose time …. and time is money …. plase do not spam any more on the web.
Thanks.
Lol! Thanks for the honest observations. 🙂
thank ajo
this help me to resolve my problem.
i have a question about mysql : how to set users in mysql open source that install in ubuntu server to force them to change password in specific day ?
Saber, I have not worked on mysql as much to answer your query now.
Beautiful pic of the path on ur website!
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”.
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.
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 dude. its work =)
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
I am having the exact same problem.
chmod 664 does nothing, I even tried 777.
Again using the default /var/www is fine, but changing the directory I always get 403 no matter what the folder permissions are set as.
Hi, I will check this again in my new setup and update if necessary.
Also internal error means there is something wrong in the config files.
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.
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
> then edit the line that says
> “” to
> “”
I am getting 403 errors, can you tell me what line exactly I need to edit? There seems to be nothing in your quotes.
There is another line a few lines down that says:
<Directory /var/www/>
This line has a trailing frontslash. I dunno if that is important or not.
Yes, the trailing frontslash is significant. Without it, I get the 403. With it, I can see my index.html file.
5th Link on the 1st page of Google Search ! Congratz !
Exactly what I needed. Thx.