用php创建apache vhost

I am trying to find a way for php to create a vhost config for apache so a user can enter there domain in and I can direct it to a given folder. Is this even possible to do with php? Or would I be better off using .htaccess and mod_rewrite. I looked all over and I can't find a clear answer to this problem. Basicly, I need php to write something to apache that points a domain to a given folder.