skip to Main Content

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


  1. 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.

    <VirtualHost *:80>
        ServerName *.example.com
        DocumentRoot /var/www/html
    </VirtualHost>
    

    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.

    Login or Signup to reply.
  2. 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…

     # get the server name from the Host: header
     UseCanonicalName Off
    
     # this log format can be split per-virtual-host based on the first field
     LogFormat "%V %h %l %u %t "%r" %s %b" vcommon
     CustomLog logs/access_log vcommon
    
     # include the server name in the filenames used to satisfy requests
     VirtualDocumentRoot /www/hosts/%0/docs
     VirtualScriptAlias /www/hosts/%0/cgi-bin
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search