How to share common codebase across multiple domains with different configurations

I’m running multiple websites on one server that are basically the same concept but with small differences. Think of it like different themed versions of the same site - they need different logos, colors, and maybe some text changes, but the core functionality is identical.

Right now I’m copying the same PHP and JavaScript files to each domain folder, which means when I fix a bug or add a feature, I have to update it in multiple places. This is getting really annoying and I keep forgetting to update all copies.

Is there a way to have one main set of files that all domains can use, but somehow tell each domain which theme or config to load? I’m thinking maybe through some kind of include system or configuration file.

I’m pretty new to server configuration stuff, so I’m not sure if this needs special hosting setup or if there’s a simple way to do it. My sites use PHP with MySQL databases.

Any tips on how to approach this would be awesome!

another approach is using htaccess to set environment variables based on domain name. i do this with SetEnvIf directive that checks SERVER_NAME and sets a variable like SITE_CONFIG. then your php code can read $_SERVER[‘SITE_CONFIG’] to load the right config file. keeps everything in one folder but each domain gets its own settings automatically.

I faced this exact scenario when managing several client sites with similar requirements. The solution I implemented uses a single codebase with environment-based configuration detection. Create a central directory outside your web roots containing all your PHP files and shared resources. Then, in each domain’s public folder, place only an index.php file that defines the site identifier and includes the main application. The main application reads this identifier and loads the corresponding configuration file containing theme paths, database credentials, and site-specific variables. This approach eliminated my update headaches completely since bug fixes and new features only require changes in one location. I also use symbolic links for shared assets like JavaScript libraries while keeping site-specific assets like logos in their respective domain folders. The setup works seamlessly with standard shared hosting and requires no special server configuration.

oh intresting! have you considerd using subdirectories instead of seperate domains? like mainsite.com and mainsite.com? that way you could have one central config that checks the URL path and loads diffrent themes acordingly. might be simpler than the htaccess route - what kind of hosting setup are you working with?