Lukas238 / xampp-vhost-creator

Batch script to create XAMPP Virtual Hosts.
13 stars 5 forks source link

Batch Script: XAMPP Virtual Host Creator

This is a small script that facilitates the configuration of virtual hostings in xamp on windows.

Initial configuration

Config.ini

All confgurations will be saved in the Config.ini file in the same folder as the script.

If this file does not exist, the script will try to create it dynamically.

Script variables

The first time the script is run, it will attempts to locate the configuration file to load the initial settings.

If not found it will try to create it dynamically with the help of the user.

  1. XAMPPDIR: The installation path of Xampp | Defautl: C:\xammp
  2. BASEURL: The document root for Xampp | Default: C:\xammp\htdocs\
  3. PREFIX: The prefix for the virtual host domain | Defualt: dev
  4. SUFFIX: The suffix for the virtual host domain | Defualt: local

How to use

When executed the script prompts the user to complete two values.

  1. Domain name: [prefix][domain][local]
    Ex.: For the domain dev.mysite.local, just enter the text mysite.

  2. Path to site root (relative to C:\mysitesfolder).

  3. The script will ask the user to confirm the values.

  4. And it will save the all the configurations in the appropriate files.

    • C:\Windows\System32\drivers\etc\hosts
    • C:\xampp\apache\conf\extra\httpd-vhosts.conf
  5. Now you just have to restart apache for the changes to take effect.

Notes

This is an example of the code generated by the script:

  1. Domain: dev.mysite.local

  2. Virtual Host:

    ###leandrogarcia###
    <VirtualHost *>
       DocumentRoot "C:\xampp\htdocs\mysitefiles\"
       ServerName dev.mysite.local
       <Directory "C:\xampp\htdocs\mysitefiles\">
           Order allow,deny
           Allow from all
       </Directory>
    </VirtualHost>