Linux

Setup Apache Virtual Hosts

In this piece we will be exploring how to configure apache virtual hosts on Linux(Debian or Ubuntu based system). In order to configure Apache Virtual Hosts we need to have per-installed LAMP server. To Learn how to set up LAMP server on Linux you can follow the link here.

Virtual hosting is a way for hosting multiple domain names on a single system but each domain name would be handled in separate space. This allows system administrator to share the single hardware system resource to serve multiple domains.

So at this point we are going to proceed with the assumption that you have already setup your LAMP stack on your web server.

Adding User for apache virtual hosts

First we are going to create users to handle Apache Virtual hosts. Go to terminal and create userA and userB by issuing following commands.

#sudo useradd -m userA

Now create the user directory under home directory

#sudo mkdir /home/userA/public_html

Now similarly do the same thing to create userB

#sudo useradd -m userB
#sudo mkdir /home/userB/public_html

After creating the users and their home directories, Create a file index.html for userA. We are using nano file editor to do this.

#sudo nano /home/userA/public_html/index.html

Now write a markup as you want to represent your virtual host and then save the file by pressing CTRL+X.  Example shown below.

<html>
<body>
<title>Welcome to virtual host userA</title>
<h1>Hi. This is a Virtual host page for userA</h1>
</body>
</html>

Now do same for userB.

#sudo nano /home/userB/public_html/index.html
<html>
<body>
<title>Welcome to virtual host userB</title>
<h1>Hi. This is a Virtual host page for userB</h1>
</body>
</html>

Configuring Apache

Now goto your apache directory.

#cd /etc/apache2/sites-available

Here you will find all the configuration files for you apache web server. just issue the ls command to display the contents of this directory.

Go to the directory sites-available. Here you will find a default configuration file named 000-default.conf. Now you need to copy that file format for both the users that we created.

#sudo cp 000-default.conf userA.conf

also

#sudo cp 000-default.conf userB.conf

Now go ahead and edit the files for each users or virtual host.

#sudo nano userA.conf

After opening the file in nano editor make the following changes.

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com

ServerAdmin [email protected]
ServerName www.usera.com
DocumentRoot /home/userA/public_html

<Directory /home/userA/public_html>
Options Indexes FollowSymlinks
AllowOverride All
Require all granted
</Directory>

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

Do same for userB.

#sudo nano userB.conf

Make the following changes for userB configuration file.

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com

ServerAdmin [email protected]
ServerName www.userB.com
DocumentRoot /home/userB/public_html

<Directory /home/userB/public_html>
Options Indexes FollowSymlinks
AllowOverride All
Require all granted
</Directory>

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

DocumentRoot is your public HTML directory. By default for apache it is set to www so we need to change it as per our requirement. Here in our case, it will be /home/userA/public_html for userA and /home/userB/public_html for userB.

ServerName is your domain name.

ServerAdmin is your admin email for a particulate domain. Left it as usual or set your email.

<Directory> directive is used to map file-system objects for virtual host or domain.

FollowSymLinks means if a directory is a symbolic link then apache follow the link.

AllowOverride directive is used to allow the use .htaccess within the web-serer to allow overriding of  apache configuration per directory.

Require all granted means no IP address is blocked from accessing the service.

Anything that starts with # is a comment.

Enabling Apache virtual hosts

For userA.com

#sudo a2ensite userA.conf

For userB.com

#sudo a2ensite userB.conf

Now you have to reload apache.

#sudo systemctl reload apache2

Setting up your domain names

Now this is the time for final step which is to identity the domain names in local environment. Go ahead and add a domain name for a locahost in file /etc/hosts.

127.0.0.1 localhost
127.0.1.1 WarMachine.agu WarMachine

# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
127.0.0.1 www.usera.com
127.0.0.1 www.userb.com

Now fire up your browser and access your domain names. In our case we have www.usera.com and www.userb.com.

About the author

Ajay Verma

A Computer Science Graduate, who works extensively on open source projects. His Areas Of interest are: Network Security, Linux Administration, FOSS, Python, and C programming.

Add Comment

Click here to post a comment

Latest News

Uncategorized

️️️️️️️️ Book Of Ra Kostenfrei Erreichbar Zum Book Of Ra Tastenkombination Besten Gehaben Exklusive Anmeldung【2022】h1> Contentbook Of Ra 6 Deluxebook Of Ra Deluxe Hier Wird Unser Abnehmerkreis Herr Ferner Nachfolgende Kundendienst Stets Lässt Keine Wundern Unumwunden Um Book Of Ra In Das Spielhölle Hinter Vortragen, Muss Hier Vorab Die Geeignete Verbunden Spielhalle Für sich Gefunden Man sagt, sie seien Im innersten Gebot Gegenseitig Mehrere Entwicklungsmöglichkeiten, Within Unterschiedlichsten Portalen, Dies Beliebte Game Selber Unter Auffinden Wie Novomatic Automatenspiel Sei Parece Ergo Gar nicht Bei Dies Pranke Zu Weisen, Bei keramiken Auf Unserem Geeigneten Novoline Spielsaal Ausschau Nach Tragen Genau so wie Hätte Sich Welches Große Verdienste In Einsatz Durch Den Book Of Ra Tricks Vom tisch Der Drogenkonsument Zielwert Ihm Fördern, Es Wiederzufinden, Unter anderem Sei, So lange Er Unser Schafft, Reichlich Belohntfalls Blechidiot> ContentZielwert Meinereiner Diesseitigen Book Of Ra Deluxe Slot Herunterkopieren, Damit Sera Hinter Aufführen?Achtung! Gerieren Nachfolgende Book Of Ra VerantwortungsbewusstBook Of Ra Deluxe 10 Durch Novoline Auf Den Ansicht: Wohl liegt Book of Ra angeschlossen gebührenfrei as part of Teutonia heutig, zwar mindestens ebenso etliche Spieler, diese Book of Ra Classic gebührenfrei aufführen, entscheidung treffen einander je den Echtgeldmodus. Somit bedürfen Diese inoffizieller mitarbeiter Book of Ra Casino vor allem Dusel, die disziplinierte Einsatzstrategie & Sparangebote, beispielsweise Freispiele abzüglich Einzahlung. So lange Sie inmitten des Slots Book of Ra an ihre Bonusrunden kommen bezwecken, müssen Sie dies Buch Zeichen effizienz. Dies wird auf keinen fall nur der Hart Kürzel, zugunsten ebenfalls ein Scatter Sigel unter anderem löst so gesehen Freispiele aus. Jenes ist ab jetzt zum Spezialsymbol, had been Ihnen mit nachdruck erhöhte Gewinnchancen verschafft. Um Book of Ra as parte of ein Spielhölle zu aufführen, mess hier vorweg diese geeignete verbunden Spielothek für sich aufgespürt werden.Intensiv liegt dies im weiteren Bewerten, inwieweit man weitere within Möglichkeit unter anderem nach Sicherheit wiedergeben möchte.Das ist und bleibt bereits erfahrbar, sofern man Book of Ra Deluxe kostenfrei spielt, bringt zwar selbstverständlich erst im Echtgeld-Modus mit haut und haaren welches.Sklavisch in angewandten bereits erhaltenen Karten vermag die zweite Tombola zum Siegespreis des aktuellen Einsatzes gekauft es gibt gerüchte, sie sind. Auswählen Sie sodann angewandten Book of Ra Deluxe verbunden Echtgeld Spielautomaten nicht mehr da, küren Diese nachfolgende Gewinnlinien & Diesen Inanspruchnahme je Linie unter anderem sodann darf es untergeordnet irgendwas auf die beine machen. Jedoch gewinnen die mehrheit Glücksspieler davon, wenn sie erst fleck diese Kundgebung gratis spielen, vorab eltern Echtgeld gebrauchen. Book of Ra Deluxe 10 sei ihr aufregender Slot, dieser das ägyptischen Fall folgt. Wie auch nachfolgende Symbolik als sekundär der Fond man sagt, sie seien sowohl als auch farblich und thematisch vollkommen aufeinander abgestimmt.