Create the following bash file and put it in the directory you want to use as apache root directory
#!/bin/sh
sed 's!\DocumentRoot .*!DocumentRoot '"`pwd`"'!' /etc/apache2/sites-available/default > default
sudo mv default /etc/apache2/sites-available/
sudo /etc/init.d/apache2 restart