I have done something very similar with some projects at work.
You make your domain with all subdomains point to the server in DNS. The webserver is configured to receive all requests for that domain, and the same application instance is run for every request (*.domain.com -> /var/www/youapplication/). Then you use apache rewrites to detect if request has "www" or something else as subdomain. If not "www", then rewrite the request to "www.domain.com/r=blog/view&username=%1"
The is not a detailed recipie, but gives you the idea of what to do.
My last project uses one instance of an application for multiple customers. Each customer is separated with its own configuration file, and the index.php file will detect which subdomain is requested, and load the appropriate configuration file.
If you want a different db for each subdomain (=user) you can do this like below.
But you have to create the db by a script on user registration.
Define a const (for example SUBDOMAIN_DBNAME) with the value of the subdomain in your index.php
//extract the subdomain and add a prefix 'subdomain_' to the dbname