How to create Subdomain on Apache 2

Discussion in 'Server Operation' started by Gufran, Sep 2, 2011.

  1. Gufran

    Gufran New Member

    Hi,
    Is there any way I can create a subdomain on my Server using console ?
    I do not use any control panel so I want to do it via SSH.
     
  2. zcworld

    zcworld New Member

    hi
    you meaning an vhost
    like (top level domain)
    note ** when you turn on vhosting your default /var/www/html site will go away (most times)

    mysite.com
    and you want
    x1.mysite.com
    x2.mysite.com


    type of deal ?
    if so , its just an easy

    at the command line
    you can change this for your own needs
    type in
    mkdir -p /var/www/vhost/x1.mysite.com/htdocs
    mkdir -p /var/www/vhost/x1.mysite.com/logs
    mkdir -p /var/www/vhost/x1.mysite.com/cgi-bin

    mkdir -p /var/www/vhost/x2.mysite.com/htdocs
    mkdir -p /var/www/vhost/x2.mysite.com/logs
    mkdir -p /var/www/vhost/x2.mysite.com/cgi-bin



    ==== centos / redhat / fedora ====
    chown -R apache:apache /var/www/vhost
    OR
    === deb / Ubuntu ====
    chown -R www-data:www-data /var/www/vhost


    chmod -R 775 /var/www/vhost

    (you may want to check the chmod levels there )

    i know mainly where the redhat and its clones keep the apache conf files
    so you may need to look around for the deb and its clone apache files


    open this file and add to the bottom of it the command than quite and save

    vi /etc/httpd/conf/httpd.conf

    NameVirtualHost *.80


    <VirutalHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/vhost/x1.mysite.com
    ServerName x1.mysite.com
    ServerAlias www.x1.mysite.com
    ErrorLog /var/www/vhost/x1.mysite.com/logs/error_log
    CustomLog /var/www/vhost/x1.mysite.com/logs/access_log common
    ScriptAlias /cgi-bin/ /var/www/vhost/x1.mysite.com/cgi-bin/
    </VirutalHost>

    <VirutalHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/vhost/x2.mysite.com
    ServerName x2.mysite.com
    ServerAlias www.x2.mysite.com
    ErrorLog /var/www/vhost/x2.mysite.com/logs/error_log
    CustomLog /var/www/vhost/x2.mysite.com/logs/access_log common
    ScriptAlias /cgi-bin/ /var/www/vhost/x2.mysite.com/cgi-bin/
    </VirutalHost>




    save and quit


    than you get access to them update your DNS server records
    or edit the hosts files on your system that u will be trying to access the sites from and add

    <IP_OF_WWW_BOX> x1.mysite.com x2.mysite.com

    save it

    windows : \windows\system32\drivers\etc\hosts
    linux : /etc/hosts
     

Share This Page