You need to set up a wildcard DNS record to catch all the subdomains and send them to you on the web server.
Then you need to configure Apache to catch all named virtual hosts and send it to a directory.
In the directory, you must install htaccess to send all requests to a single script that will read the subdomain from the server variables and process it accordingly.
source share