In my development machine I always like to move the default /var/www
directory to my home directory, e.g. /home/tareq/www
. It’s very simple to do. Open the /etc/apache2/sites-available/default
file with administrator previledge and change the document root as you want
[shell]$ sudo gedit /etc/apache2/sites-available/default[/shell]
Now change the file like this:
[shell highlight=”1,6″]
DocumentRoot /home/tareq/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/tareq/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
[/shell]
Now restart your apache
[shell]$ sudo /etc/init.d/apache2 restart[/shell]
Update
According to Nasim vai, there is a more elegant solution with a single line command :-
[shell]$ sudo rm -r /var/www; sudo ln -s /home/${USER}/www /var/www[/shell]
sudo chown -R $USER /var/www; ln -s /var/www /home/${USER}/www
That’s all you need! 🙂
@nsmgr8 I am using my home directory in a separate partition. If somehow my ubuntu installation gets corrupted, my home directory will be safe and I can install the system without much trouble. So I prefer to move the www directory to home instead a symbolic link 🙂
@tareq Then try the other way around
sudo rm -rf /var/www; sudo ln -s /home/${USER}/www /var/www
The point is not to touch default settings. Of course, there are thousand other ways to do it.
@tareq
Then try the other way around
sudo rm -r /var/www; sudo ln -s /home/${USER}/www /var/www
The point is not to touch default settings. Of course, there are thousand other ways to do it.
@nsmgr8 Thins one seems nice indeed 😀
Thanks ! 😀
The symlink (second) way is better imo as it avoids changing config files. You should ad a caveat to your comment though warning people that they are deleting their current doc root and all files within using that method. 🙂
good job. thanks so much ^^
Hi.
thanks for your article.
how to do it in xubuntu 14.04 using xampp?
I haven’t tried xampp, using xampp on linux is not a good idea. Use the LAMP stack.
will it not work withouth the whole Directory thing that you have to add? what is that exactly?
I actually like changing config files better because that’s a standard process with any other service. I don’t have to try to remember a different method or process. I do it like dns, dhcp, samba, etc – so why deviate from that even if it’s easier via one line change? Stick with a standard and you know where to go always.