I think the best way is to start with pre designing your site structure . determine all the possible scenario that may accrue in any giving situation set your style sheets and your html file inside functions so that way it's easier to define your templates on the fly
<? // i.e.
function html() { ?><? } ?>
if you design all your layout in this fashion it should be easy to control site design of the fly
also A problem I ran into when copy preset file to a folder made on the fly beware of ownership this will take all ownership away those file copied to that dir most of this should be easy to do if it is prepared correctly best thing to do is create function or classes to run everything you need to dynamically run your site.
This should be a good start to get a idea on the structure you may need but only when you start determining your site functionality is when you can determine the best way to approach this project.
Good Luck