A. Shifting the Document Root of Apache:

If you want to shift the Document root of Apache, just follow the steps:

1. Copy the default settings to the new one

sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/mysite

2. Set the new Directory path:

sudo gedit /etc/apache2/sites-available/mysite

### Change the Directory directive, replace <Directory /var/www/> to <Directory /your/documentroot/path/>

3. Enable new site and disable default one:

sudo a2dissite default && sudo a2ensite mysite

### a2ensite (apache2enable site) and a2dissite (apache2disable site).

4. Restart the apache server:
sudo /etc/init.d/apache2 restart
service apache2 restart

B. Shifting the Data directory of MySql:

Here new_path should be replaced with your new path location

/etc/init.d/mysql stop
cp -R -p /var/lib/mysql /new_path

Then create a symlink
ln -s /new_path/mysql/ /var/lib

[Note: do not forget to add mysql/ at the end of the new path]

In this way you DO NOT need to touch the mysql config: /etc/mysql/my.cnf

If you are using Ubuntu, then you have to follow one more step to make MySql work. Ubuntu use a software called AppArmor that specifies different paths for MySql.
In the terminal, enter the command

sudo gedit /etc/apparmor.d/usr.sbin.mysqld
Make commented the related lines and add new one that specify new location:

# /usr/lib/mysql/plugin/ r,
# /usr/lib/mysql/plugin/*.so* mr,
/Your/Path/mysql/plugin/ r,
/Your/Path/mysql/plugin/*.so* mr,
# /var/lib/mysql/ r,
# /var/lib/mysql/** rwk,
/Your/Path/mysql/ r,
/Your/Path/mysql/** rwk,

Now restart AppArmor:
/etc/init.d/apparmor restart

Finally restart MySql:
/etc/init.d/mysql restart

Now you all set with the new location. Congrats!

N.B. I use this settings very often with Ubuntu 12.04 LTS.