The Apache Web Server offers the possibility to run multiple web-sites with different hosts simultaneously. The pages www.MeineSeite.de and www.Beispiel.de can therefore run on the same server and Apache. A requirement for this is that every host is connected to a virtual host in Apache.
On Linux (Debian/Ubuntu) virtual hosts are defined in the directory /etc/apache2/sites-available/. By default there is already one file named default created for one virtual host. It might look like this.
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/htdocs <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/htdocs> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog /var/log/apache2/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/access.log combined </VirtualHost>
This ensures that everything, that arrives on the Apache on port 80, is leaded to the contents of the directory /var/www/htdocs.
So if the other site www.Beispiel.de should operate on the same Apache on port 80, but has a completely different content, you need to tell Apache that the content of this page in www.Beispiel.de is lying in a different directory. In other words: the new site needs a different „DocumentRoot“.
So first you create another directory for the new site – in this case, for example,
and copy the contents of the new page in that directory.
Then set the proper permissions for the Apache to the directory and its contents with the command
chown -R www-data : www -data / var / www / example
Now create the virtual host.
For the new virtual host another file needs to be created in the directory /etc/apache2/sites-available/. So cpopy the file deault and name the new file to the name of the new page. In this case
root@arm:~# cd /etc/apache2/sites-available/ root@arm:/etc/apache2/sites-available# cp default Beispiel.de
Now the new file needs to be edited so that the appropriate host will use to correct the „DocumentRoot“.
So open the file with an editor to insert the row with the server name, the „DocumentRoot“ and adjust the settings for the Directory.
For the page www.Beispiel.de:
<VirtualHost *:80> ServerAdmin webmaster@localhost ServerName Beispiel.de DocumentRoot /var/www/beispiel <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/beispiel> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> . . . </VirtualHost *:80>
These entries now ensure that all requests to the Apache, which are directed to the site under the host www.Beispiel.de are forwarded to the contents in the directory /var/www/beispiel.
And cause of the settings in the file default all others request are still forwarded to the directory /var/www/htdocs.
Then the new page only needs to be activated.
For this use the command:
And that’s it.