You will have to have PHP running as a priviledged user. Then its a simple matter of writing to your conf, then restarting apache. Problem is the security implications of having PHP running as a priviledged user. Any slip up in input validation could cause BIG TROUBLE.
Here is a more secure idea. Instead of creating actual sub-domains.
Add an 'A' record in your DNS zone for * that points to your web server.
Example: * IN A 123.0.56.3
Add a ServerAlias in your virthost
Example: ServerAlias domain.
Basically, any third level domain will resolve to your site now.
Then, make your index page a wrapper.
Everytime someone creates an account, you add that subdomain to a database along with a corresponding page to redirect to. Then if they hit your index page again using the subdomain, depending on HTTP_HOST, you select the redirect out of the database and
header("Location: redirect");