Ubuntu Apache2 : Change default DocumentRoot /var/www
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.
STEP1: First you need to make the directory to which you want to change the DocumentRoot to. Preferably make this directory in your home folder so that you have all the permissions to edit the files that are kept in the folder. So issue the command
DocumentRoot /var/www/ Change it to
To do this, we must create a new site and then enable it in Apache2.
1.To create a new site: /etc/apache2/sites-available/default
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
///////////////////////////So if you want to change the DocumentRoot in apache2 you will not find the setting under httpd.conf. To chance the DocumentRoot of the apache2 server follow the steps:
STEP1: First you need to make the directory to which you want to change the DocumentRoot to. Preferably make this directory in your home folder so that you have all the permissions to edit the files that are kept in the folder. So issue the command
mkdir ~/name_of_your_folderSTEP2: To change the DocumentRoot you would need to edit the file default file placed in /etc/apache2/sites-available . So issue the command
$sudo gedit /etc/apache2/sites-available/defaultIn this file you would see something like
DocumentRoot /var/www/ Change it to
DocumentRoot /home/username/name_of_your_directory/
On line 9 you would see something like this
<Directory /home/username/name_of_your_directory/> STEP3: Save the file. Go to the terminal and issue the command
<Directory /var/www/>
Change it to<Directory /home/username/name_of_your_directory/> STEP3: Save the file. Go to the terminal and issue the command
$sudo /etc/init.d/apache2 restartAnd its done. Now place any of your file in the folder you made and you would be able to see the file by going to http://localhost/
No comments:
Post a Comment