Create apache Virtual Hosts In Ubuntu

DATE POSTED: 06/03/2019

In this post we will explain how to create the virtual hosts in ubuntu.

What is: Apache?

Apache is the most important used web server software in the world because it is an open source software. This web server developed and maintained by Apache Software Foundation.

1) Install the apache web server on your ubuntu server

$ sudo apt-get install apache2

2) Make the new directory for the new domain.

sudo mkdir -p /var/www/html/

3) You can use the code for your new domain.

vi /var/www/html/
 <h1>Hello, This is a test page for website</h1>

3) New configuration file for domain.

sudo vi /etc/apache2/sites-available/

<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.

   DocumentRoot /var/www/html/

# 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

4) Enable virtual host configuration files.


5) Run this command and check the apache files is syntax is correct or not.

apachectl configtest

6) If made any change in the apache related configuration you need to restart apache web server to take a look upon the changes.

systemctl restart apache2

Congratulations! You have completed the virtual host setup and now be able to access your websites.

Thanks for using pheonix solutions.

You find this tutorial helpful? Share with your friends to keep it alive.

Leave a Reply