Quickly create multiple websites (http and https) after a standard Apache installation to get rolling right away!
Web developers or systems administrators who want to quickly set up multiple websites on a freshly installed Apache web server for development or testing purposes.
Developed and tested on a vanilla Ubuntu system.
End results: Quickly set up multiple websites as Named Virtual Hosts.
This script needs you to supply two parameters:
- The webserver home directory where to place the websites (defaults to /var/www/)
- The domains you want to be created.
- Important note: use domain names without including 'www'. i.e. domain1.com , not www.domain1.com
This script will do the following:
- Create the Apache site conf file for each website (/etc/apache2/sites-available)
- domain1.com will be permanently redirected to www.domain1.com
- Auto create self-signed SSL keys for each website (/etc/apache2/ssl)
- Create web home directories with barebones index.html
- Auto enables Apache SSL module
- Auto enables both HTTP and HTTPS websites
- Add the domains to your /etc/hosts and couple them to 127.0.1.1 (in the localhost range 127.0.0.0/8).
How to run
chmod u+x setup_domains.py sudo ./setup_domains.py -h (view the help screen for the switches you need to set)
-w WEBDIR, --webdir WEBDIR Location of webserver home directory, defaults to /var/www
-d DOMAINS [DOMAINS ...], --domains DOMAINS [DOMAINS ...]
List of domains, defaults to domain1.com domain2.com.
Don't include the 'www.' prefix since that will be taken care of.
sudo ./setup_domains.py -w /var/www -d domain1.com domain2.com
--or--
Look at example.py for how to incorporate the function into your own script