sub domains

How can i create sub domains like the following example:

www.user1.myapp.com

www.user2.myapp.com

etc.

What i want to do is create a multi tenant app and associate users with a sub domain. Please provide direction.