Ubuntu Apache2 : Change default DocumentRoot /var/www

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 givenhere.

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 theErrorLog andCustomLog 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 (apache2enablesite) and a2dissite (apache2disablesite).

sudo a2dissite default && sudo a2ensite mysite

Finally, we restart Apache2:

sudo service apache2 restart

comefrom:http://www.ajopaul.com/2010/05/01/ubuntu-apache2-change-default-documentroot-varwww/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值