I have a php code/site at xyz.com. Now I want to run the same site using multiple domains means when somebody open domain1.com, domain2.com ,domain4.com, so on urls, it should run the code/side that is at xyz.com

I know one way to do this. I can host all these domains to the server where xyz.com is hosted so all domains will point to same peace of code/site.

n above solution i need to hosted the domains manually. Is there any other way to do this as I want to add domains dynamically?

Thanks in advance!


If you have control over your Apache configs on your server, just change the default virtual host's DocumentRoot to /your/site/root. As long as your domains' A records (or you can use CNAMEs) all resolve to your Web server's IP address, Apache will dish up the default website if there's no match for another virtual host.

This is a very common method of doing it, so unless you need to have separate Web servers for each domain, there's nothing more manual with this method than any other method (like using rsync to copy your PHP files to another server); DNS needs to be setup regardless.

You can setup wildcard DNS for sub-domains you control so that *.yourdomain.com (foo.yourdomain.com, bar.yourdomain.com, etc.) all resolve to the same A record, but not with TLDs (unless you happen to own the .com TLD).

| improve this answer | |
  • 2
    Or set up VirtualHosts for each server and point their DocumentRoots to the same dirs. This will allow you to have per domain logs and make other per domain changes should you wish to do so. – Jason Tan May 3 '10 at 14:27
  • This is what I'd do (although I think you meant, "VirtualHosts for each domain"), but I think that might be too "manual" for him unless he scripts it. – gravyface May 3 '10 at 14:32

If you have ssh access, you could use something like rsync to keep the files on the sites all the same. You would update the master domain, and the changes would be copied to the other servers you setup rsync with. This would probably the best least hassle method of doing it.

Another way is to create a secure connection to the main server via ftp or ssh, get the file via fopen and then run it in your script.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy