Setting up a web server like Apache only gives us one domain, which is
http://localhost associated with the
127.0.0.1 IP address or another address.
Since we are only allowed to have one website by a web server, we can bypass this limitation by creating different directories for each website on the localhost.
We have two directories in
http://localhost. You can add as many as you want.
While this solution may work, note that:
To avoid issues in a production server, it would be better to have a local environment similar to the production one.
To allow more than one website on one system or web server, each with their own domain name, we need to activate the virtual host feature on that server. For instance,
www.facebook.cd can both be hosted on the same web server.
There are many types of virtual host methods, but the most commonly used one is a name-based virtual host. It allows one IP address (e.g.,
127.0.0.1) to host more than one website (host name). This approach allows an unlimited number of servers, ease of configuration and use, and requires no additional hardware or software.
For each domain you want, you’ll need to create a virtual host.
The configuration file responsible for this is
In my installation, it is located at:
gediteditor using the following command:
sudo gedit /opt/lampp/etc/extra/httpd-vhosts.conf
<VirtualHost *:80> ServerAdmin firstname.lastname@example.org DocumentRoot "/opt/lampp/htdocs/time-tracker" ServerName local.tracker.com ServerAlias www.local.tracker.com ErrorLog "logs/tracker.com-error_log" CustomLog "logs/tracker.com-access_log" common </VirtualHost>
DocumentRootdirective, we specify where our project is located.
ServerAliasis the domain name we want the server to respond to. In my case, the server will respond to
hostsfile. In Debian GNU/Linux it is located at
sudo nano /etc/hosts
Ctrl + Xand
httpd.conf. Open it to allow virtual host:
sudo nano /opt/lampp/etc/httpd.conf
virtual hostsline (
ctrl + Wand write
#sign before the line) this line.
sudo /opt/lampp/lampp restart
Virtual hosting is a technique used to allow one web server to host more than one domain. The most used virtual hosting type is the name-based one.
You can create a virtual host on Debian GNU/Linux following these three steps:
Create a new virtual host in
Register it in
Enable virtual host in
View all Courses