The vaddhost utility is an interactive, command-line program that automates the process of configuring Virtual Subhosts. After launching vaddhost, it will ask you several questions about the configuration of your Virtual Subhost and provide you with default responses. As you answer each question, vaddhost will display the <VirtualHost> definition with each new piece of information.
Once you have responded to all questions, vaddhost will create necessary directories, add the <VirtualHost> entry to your main web server configuration file (~/www/conf/httpd.conf), and create a backup of your old ~/www/conf/httpd.conf file in your ~/www/conf directory. You can remove these backup files at your discretion.
To use vaddhost, connect to your Virtual Private Server via SSH, su to root, and do the following:
Access the current DNS registry for the domain, and set the TTL (Time To Live) on the current DNS to 0.
Add your domain to your name servers.
Run the vadduser command to add the primary user for this virtual host. You will want to create a unique username, and not a generic one (e.g. webmaster, as the Virtual Host will be tied to this username). Permissions MUST include web for this user to have Virtual Hosting.
Virtual Hosting is created in a specified user's www directory. Each web-enabled user account is capable of managing multiple Virtual Hosts.
# vadduser
Run the vaddhost command.
# vaddhost
Enter the username created in step one above, or press Enter to see a list of users. All hostnames (Virtual Hosts) you enter below will be associated with this username account. For security reasons, you may not select 'root' as the vhost user.
Virtual Host Names identify which domain names will be associated with the Virtual Subhost definition that vaddhost will add to your ~/www/conf/httpd.conf file. You may specify one or more domain names with each Virtual Subhost definition.
We suggest you enter the primary domain first, followed by the 'www' cname (i.e., www.SUBHOST-DOMAIN.NAME). You can also include domain names which will also point to this virtual host (e.g., SUBHOST-DOMAIN.net and SUBHOST-DOMAIN.org may simply be aliases for SUBHOST-DOMAIN.com).
If you plan on serving secure content for this virtual host, you may now enable SSL for this virtual host, allowing it to serve web pages and accept form submissions over an encrypted link.
The Host Admin Email Address identifies the email address of the person responsible for the Virtual Subhost web site. The default email address is webmaster and will alias to the Virtual Private Server E-Mail User Account, you created in step one. This will rebuild your virtusertable database.
The Virtual Host Document Root is the directory where the web site content for the Virtual Subhost will be stored (i.e., web pages) and served from. The value of the Document Root is defined with respect to the username you assigned to this Virtual Host, and their www directory. For example: /home/USERNAME/www. The default value will use the domain name as the Document Root directory name (i.e. /home/USERNAME/www/SUBHOST-DOMAIN.NAME).
The default specifies separate transfer and error log files for each Virtual Subhost. This is an optional feature. If you do not wish to store separate log files for the Virtual Subhost, the transfer and error log information will be stored in the web server's master log files. If you do wish to store separate transfer and error log files, vaddhost will provide you with several options based on the input you provided for the Virtual Subhost Document Root.
The default will configure a cgi-bin directory for your Virtual Subhost. This is also an optional feature. The ScriptAlias directive defines where CGI scripts are stored for the Virtual Subhost.
You will be asked to confirm the Virtual Host entry:
<VirtualHost SUBHOST-DOMAIN.NAME www.SUBHOST-DOMAIN.NAME:80>
User USERNAME
Group USERNAME
ServerName SUBHOST-DOMAIN.NAME
ServerAdmin webmaster@SUBHOST-DOMAIN.NAME
DocumentRoot /home/USERNAME/www/SUBHOST-DOMAIN.NAME
ScriptAlias /cgi-bin/ "/home/USERNAME/www/cgi-bin/"
<Directory /home/USERNAME/www/cgi-bin>
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>
CustomLog /home/USERNAME/www/logs/access_log combined
ErrorLog /home/USERNAME/www/logs/error_log
</VirtualHost>
<VirtualHost SUBHOST-DOMAIN.NAME www.SUBHOST-DOMAIN.NAME:443>
SSLEnable
User USERNAME
Group USERNAME
ServerName SUBHOST-DOMAIN.NAME
ServerAdmin webmaster@SUBHOST-DOMAIN.NAME
DocumentRoot /home/USERNAME/www/SUBHOST-DOMAIN.NAME
ScriptAlias /cgi-bin/ "/home/USERNAME/www/cgi-bin/"
<Directory /home/USERNAME/www/cgi-bin>
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>
CustomLog /home/USERNAME/www/logs/access_log combined
ErrorLog /home/USERNAME/www/logs/error_log
</VirtualHost>
Confirmation will create the Virtual Host entry, and restart Apache.