how to create a sub-domain in Apache or mysql database and make a user name and password to access it?

Posted on Jun 16, 2008 under domain news and reports |

One Response to “how to create a sub-domain in Apache or mysql database and make a user name and password to access it?”

  1. A subdomain is configured by virtual host entries in httpd.conf.
    Here is an example of what the file should look like:

    Listen 80
    NameVirtualHost *

    <VirtualHost *>
    ServerName http://www.domain.com
    DocumentRoot /home/httpd/htdocs/
    </VirtualHost>

    <VirtualHost *>
    ServerName subdomain.domain.com
    DocumentRoot /home/httpd/htdocs/subdomain/
    </VirtualHost>

    To create a username and password you will need to create or edit your .htaccess file.

    You need at least four lines in .htaccess to set up password protection:
    AuthName "Realm name"
    AuthType Basic
    AuthUserFile /BASEDIR/.htpasswd
    require valid-user

    /BASEDIR/ is the path to your root directory.

    AuthName: Realm name a piece of text that appears on the dialogue box asking for the password. See what it does in practice and then you can decide what text you would like here.

    AuthType: Only Basic is possible at present.

    AuthUserFile: The existence of the AuthUserFile line suggests that you can call the .htpasswd file something else. That is true, but is best to call it .htpasswd, so that nobody can view its contents.

    require: This says that any user validated by password is allowed.

    As well as these entries in the .htaccess file, you will need to set up a .htpasswd file

    The format of this file is simple. It consists of a series of usernames and passwords. Each line holds one username and the single password associated with it, separated by a colon. Here is an example:

    frances:WrU808BHQai36
    john:iABCQFQs40E8M
    lisa:FAdHN3W753sSU

    You may think these passwords are rather unrealistic and difficult to remember - the reason for this is that they are encrypted for security. The .htpasswd file does not hold the actual passwords in clear text - it holds them in a coded form. If you are running Apache (at least on Unix) there is a command called htpasswd which will translate clear text passwords into this encrypted form. What many webmasters do is use an on-line tool to do this translation.

Leave a Reply