Uptime :: Server


14.10.06

mkVhost

NOTE :: this has only being tested on FC5 system

mkVhost is a shell script used to simplify/automate the creation of Virtual Hosts on Apache webservers. This script was created and tested using Apache v2.0.54 on Fedora Core 4 Linux. However it is easily modifiable to work with any release of apache that supports the Include directive with support for Wildcards, which was not introducted until Apache 1.3.27.

Downloads
ver 1 :: statble
craz1 : Download here 21 kb
ZcWorld : mod 1 38 kb and Mod 2 30 kb

==== Screen Shots ====
from ZcWorld mod ver

Inside LAN


























Outside LAN


























==== Configuring Apache for mkVhost ====

All you need to do in order to prepare Apache for mkVhost is to make sure the following two things are set in your httpd.conf file.

NameVirtualHost *:80
Include /var/www/vhost.d*.conf

Of course you will have to modify the above two settings to meet any requirements you need, such as a specific IP Address instead of *, a non-standard port or a different path to store the generated vhost configuration files. Another thing you might want to take note of is that if you change either of these settings to something other than the default you will need to edit the vhost.template file to match the setting, or else your virtual hosts will not work correctly.


==== Configuring mkVhost ====

Before you begin to use mkVhost for the first time, you will have to take a few moments to setup the default settings for it. Open up the file mkvhost.config in your favourite editor and make any changes.

Some of the better editors are:

* JED
* VIM (Vi IMproved)
* Emacs



==== Settings ====

The following is a list of settings that can be set in the mkvhost.config configuration file.


CONFDIR
This defines where to store the generated VirtualHost configration files. This has to be the same as your Include setting in your httpd.conf file.


Default: /etc/httpd/vhost.d/*.conf


BASEDIR
This is the location where the web folders should be created.


Default: /var/www/vhosts


ADMIN
This is the email address for the default admin of the virtual hosts. Old logfiles will also get emailed to this address as they are rotated out of existance when the want_logrotate setting is enabled, so it is important that this is set to a valid email address.


Default: user@host.com


PIDFILE
This is the location of your httpd.pid file. You can find where this is by checking/setting the PidFile Directive in your httpd.conf file.


Default: /var/run/httpd.pid


apacheuser
This should be set to the username that apache runs as. You can find the correct value of this by checking/setting the User Directive in your httpd.conf file.


Default: apache


apachegroup
This should be set to the groupname that apache runs as. You can find the correct value of this by checking/setting the Group Directive in your httpd.conf file.


Default: apache


reload_apache_cmd
This should be set to the command to execute to reload your apache configration after each new vhost is added.


Default: service httpd reload


want_logrotate
If you have logrotate running on your system (most modern linuxs do), then you should set this to "yes". This will enable logfile rotation, which by default will create a new logfile every week and email old logfiles to the email address defined by the ADMIN setting. By default old logfiles will not start getting emailed until after 4 weeks have passed and old logs are ready to get pushed out of existance. All default logrotate settings can be changed by editing the logrotate.template file.


Default: yes


verbose
Have the script be more verbose about what it is doing. This can look real messy to most people.


Default: yes

==== Using mkVhost ====

Change to the folder you have extracted mkvhost to. After configuration of mkvhost you can simply run ./mkvhost.sh, please make sure you are in the folder that mkvhost.sh is in or it will not work correctly (for now anyway).


The following example creates the virtual host (www.)example.com


./mkvhost.sh example.com

Output:

Creating vhost (www.example.com) -- continue? [y/N]: y
Creating virtual host.
Creating config: /etc/httpd/vhost.d/example.com.conf
Creating folder layout in: /var/www/vhosts/example.com
mkdir: created directory `/var/www/vhosts/example.com'
mkdir: created directory `/var/www/vhosts/example.com/htdocs'
mkdir: created directory `/var/www/vhosts/example.com/tmp'
mkdir: created directory `/var/www/vhosts/example.com/logs'
mkdir: created directory `/var/www/vhosts/example.com/cgi-bin'
mkdir: created directory `/var/www/vhosts/example.com/users'
Copying default index.php
`index.php.template' -> `/var/www/vhosts/example.com/htdocs/index.php'
Setting permissions
changed ownership of `/var/www/vhosts/example.com/' to apache:apache
changed ownership of `/var/www/vhosts/example.com/cgi-bin' to apache:apache
changed ownership of `/var/www/vhosts/example.com/logs' to apache:apache
changed ownership of `/var/www/vhosts/example.com/htdocs' to apache:apache
changed ownership of `/var/www/vhosts/example.com/htdocs/index.php' to apache:apache
changed ownership of `/var/www/vhosts/example.com/users' to apache:apache
changed ownership of `/var/www/vhosts/example.com/tmp' to apache:apache
mode of `/var/www/vhosts/example.com/htdocs/index.php' changed to 0644 (rw-r--r--)
mode of `/var/www/vhosts/example.com' changed to 0755 (rwxr-xr-x)
mode of `/var/www/vhosts/example.com/htdocs' changed to 0750 (rwxr-x---)
mode of `/var/www/vhosts/example.com/tmp' changed to 0750 (rwxr-x---)
mode of `/var/www/vhosts/example.com/logs' changed to 0700 (rwx------)
mode of `/var/www/vhosts/example.com/cgi-bin' changed to 0700 (rwx------)
mode of `/var/www/vhosts/example.com/users' changed to 0755 (rwxr-xr-x)
mode of `/etc/httpd/vhost.d/example.com.conf' changed to 0644 (rw-r--r--)
Adding logrotate file: /etc/logrotate.d/httpd.vhost.example.com
ownership of `/etc/logrotate.d/httpd.vhost.example.com' retained as root:root
mode of `/etc/logrotate.d/httpd.vhost.example.com' changed to 0644 (rw-r--r--)
Apache must be reloaded before it will recognize the new vhost: example.com
Do you want to reload apache's configration now? [y/N] y
Reloading httpd: [ OK ]

[www.example.com]

Configration....: /etc/httpd/vhost.d/example.com.conf
HTML Folder.....: /var/www/vhosts/example.com/htdocs
LOG Folder......: /var/www/vhosts/example.com/logs
CGI-BIN Folder..: /var/www/vhosts/example.com/cgi-bin
USER Folder.....: /var/www/vhosts/example.com/users
Logrotate File..: /etc/logrotate.d/httpd.vhost.example.com


The script is written by Craz1 2006

***** This has been copied from http://wiki.craz1.homelinux.com/index.php/MkVhost
and edited for my release of this *********

Labels: ,