Skip to content

Instantly share code, notes, and snippets.

@faroncoder
Last active December 31, 2015 05:09
Show Gist options
  • Save faroncoder/7938883 to your computer and use it in GitHub Desktop.
Save faroncoder/7938883 to your computer and use it in GitHub Desktop.
Configuring Apache2 for webhosting multiples of websites on one ip address by using
Apache2's "Name-Domain-Based" virtual hosting websites.
This httpd.dat holds configurations for 2 websites, simply copy lines between
<VirtualHost *:80></VirtualHost>.
BIG EMPHASIS TO LEAVE *:80 untouched or whole system will fail.
you will see ## EDIT THIS ## which define the line that you can
edit whatever you like accordingly. But any lines without that notch,
is something you wouldn't want to touch.
This also customizes your apache access.log and errors.log to wherever
location on your server as you like.
<Directory></Directory> is the folder you are hosting your websites
and that will becomeS the parent level in tree system inside apache2.
i.e. /var/www as parent
/var/www/example_ca/ = location of html on www.example.ca
/var/www/sample_ca/ = location of html on www.sample.ca
<Directory "/var/www"> ## EDIT THIS ##
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
<location /cgi-bin>
AddHandler cgi-script .cgi .pl
Options -Indexes +FollowSymlinks +ExecCGI
</location>
<VirtualHost *:80>
ServerName example.ca ## EDIT THIS ##
ServerAlias www.example.ca ## EDIT THIS ##
DocumentRoot /var/www/example_ca/html ## EDIT THIS ##
<Location "/">
Order Deny,Allow
Deny from all
Allow from all
</Location>
CustomLog /path/to/your/preferred/log-folder/access.log common ## EDIT THIS ##
ErrorLog /path/to/your/preferred/log-folder/error.log ## EDIT THIS ##
</VirtualHost>
<VirtualHost *:80>
ServerName sample.ca ## EDIT THIS ##
ServerAlias www.sample.ca ## EDIT THIS ##
DocumentRoot /var/www/sample_ca/html ## EDIT THIS ##
<Location "/">
Order Deny,Allow
Deny from all
Allow from all
</Location>
CustomLog /path/to/your/preferred/log-folder/access.log common ## EDIT THIS ##
ErrorLog /path/to/your/preferred/log-folder/error.log ## EDIT THIS ##
</VirtualHost>
#!/bin/bash
sudo apt-get install -y apache2 apache2 apache2-dev apache2-threaded-dev libapache2-mod-perl2 libapache2-mod-php5
## WIRING APACHE2 DEFAULT SETTING ##
## ENABLING APACHE2 VIRTUAL HOSTING WITH HTTPD.CONF
sudo sed -i -e 's/IncludeOptional sites-enabled/#IncludeOptional sites-enabled/g' /etc/apache2/apache2.conf
sudo echo "include httpd.conf" /etc/apache2/apache2.conf
sudo echo "<VirtualHost *>
</VirtualHost>" >> /etc/apache2/apache2.conf
sudo cp -r httpd.dat /etc/apache2/httpd.conf
exit 0
@faroncoder
Copy link
Author

Combo of files for script to install apache2 and set up multiple webhosting on host machine on one ip address

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment