How to share common codebase across multiple websites on one server

I’m running multiple websites on the same server and they’re basically the same concept but with different branding. Think of it like how Stack Overflow and Server Fault work - same functionality but different themes and content focus.

Right now I’m copying the same PHP and JavaScript files to each domain folder, which means when I need to update something I have to change it in multiple places. This is getting really messy to maintain.

What’s the best way to have all my sites use the same core files? I’m wondering if there’s a way to set up includes or maybe use one shared database.

I’m pretty new to server configuration stuff. How would I set up variables in my hosting setup that tell my code which theme or database to use for each domain? Do I need special server access for this?

My stack is PHP with MySQL. If anyone can point me in the right direction or tell me what to ask my hosting company, that would be awesome!

I’ve implemented a centralized setup that may work for you. Place your shared code outside of the web root and create a bootstrap file in each domain folder. This bootstrap file will check the domain name to set the appropriate environment variables for your specific site. It can pull in configuration files containing your database details, theme paths, and various site settings. Using a single database with site identifier columns is a more efficient approach than managing multiple databases. Most hosting providers allow this configuration through their file manager or SSH access.

symlinks rly simplify things! just keep 1 master folder and link it to each domain’s dir. most shared hosts can do this, but ask them 1st. to detect domains, use $_SERVER[‘HTTP_HOST’] in PHP for loading specific configs/themes.

this setup sounds really cool! are you planning to use subdirectories for each site or keep separate domains? also, how do user accounts work across the different sites? shared logins or completely separate?