LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   add subdomain (https://www.linuxquestions.org/questions/linux-newbie-8/add-subdomain-438613/)

adnanm 04-25-2006 06:46 AM

add subdomain
 
Hello,

I have a hosting account on Centos with cPanel.

I would like to offer free subdomains to my customer.

I can add a subdomain in cpanel, and it works fine.

The questions is, How can I make a script that would do that automaticly.

All I need is a script that would add it thru shell. I would do the rest.

Thanx.

zeitounator 04-26-2006 04:34 AM

Might not be your solution but I offer to clients asking for it automatic subdomains. All it takes is a wildcard entry in their dns record and a very simple rewrite rule in their virtual host entry in apache. Then, the simple creation of a directory creates the subdomain.

Here is an example for domain blabla.com.

DNS zone file contains:
Code:

$ttl 86400
blabla.com.    IN      SOA    somenameserver.com. contact.blabla.com. (
                        2006042601
                        21600
                        3600
                        604800
                        86400 )
                IN      NS      somenameserver.com.
                IN      NS      somebackupnameserver.com
                IN      MX      10 mail.blabla.com.
                IN      MX      50 somebackupMX.com
                IN      A      x.x.x.x
www            IN      A      x.x.x.x
mail            IN      A      y.y.y.y
smtp            IN      A      z.z.z.z
*              IN      A      x.x.x.x

The virtual host entry looks like
Code:

<VirtualHost *:80>
    ServerAdmin webmaster@blabla.com
    DocumentRoot /home/[blabla.comUserHome]/www
    ServerName blabla.com
    ServerAlias www.blabla.com
    ServerAlias *.blabla.com
    CustomLog /var/log/apache/blabla-access_log combined
    RewriteEngine on
    RewriteCond  %{HTTP_HOST}                ^(^.+)\.blabla\.com$
    RewriteRule (.*)                    /home/[blabla.comUserHome]/%1/$1
</VirtualHost>

Once this is in place, the user just needs to create a directory in his home dir. It can then be accessed through http://<dirname>.blabla.com


All times are GMT -5. The time now is 08:26 PM.