is there a way to have a LAMP server and create subdomain programatically via PHP?
I don’t want to install Plesk or cPanel, I know they have API’s which lets me create subdomains. But is there a way to go around them and have a bare server with just LAMP services installed.
2
Answers
Just point all subdomains to your document root, and figure out which subdomain was accessed in your PHP code. With wildcard DNS and a wildcard virtual host, you do not need to “create” subdomains, all possible subdomains simply exist.
This is how services that hand out a subdomain to each user work. They do not actually create DNS records, edit web server config files, and restart all their services every time a user signs up.
You can look at the mass virtual hosting module provided by Apache:
With your PHP, when you want to create a new domain, simply create a new directory … and implement parts of this configuration (consult the link above) on how to configure your Apache. This will allow a seperate vhost per host … as opposed to the alternate answer which still requires more configuration work per unique hostname…