Sunday, July 26, 2020

Configure Virtual Host apache2 In Ubuntu 20.04

Configure Virtual Host  apache2 In Ubuntu 20.04

Configure Virtual Host  apache2 In Ubuntu 20.04

Do after successfull installation of LAMP

Step 1: Create web diretory of each virtual host

sudo mkdir -p /var/www/

Step 2: Change ownership from root to current user

$ sudo chown -R $USER:$USER /var/www/

Step 3: Set read permission to the Apache root directory i.e /var/www/  using command in terminal

$ sudo chmod -R 755 /var/www/

Step 4: Create demo page for host

$ sudo vi /var/www/

 <h1>Hello, This is a test page for website</h1>

Save & Close file.

Step 5:  Create configuration file for your host (

$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/

Becareful that you must save all configuration files with .conf extension at the end, otherwise it will not work.

Now update in changes in *.conf 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.

   ServerAlias www.ostechnix1.lan
   DocumentRoot /var/www/

# 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

Save & Close

Step 6:  Disable default virtual host

$ sudo a2dissite 000-default.conf

Step 7:  Enable your configured virtaul host

$ sudo a2ensite

Step 8: Test configured virtual host

$ sudo apache2ctl configtest

if all is ok shows below message

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using Set the 'ServerName' directive globally to suppress this message
Syntax OK

Step 9: Configure defined site to hosts file

$ sudo vi /etc/hosts


Step 10: Restart your apache2 server

$ sudo systemctl restart apache2

That's it.

Finally, open your installed browser and hit below url:

Other Service also provide

Let me know if you have any query.

Prime Programmer

No comments:

Post a Comment

Lead Management System(LMS) Software Online

 Lead Management System Software Online Our Leads Management System(LMS) Features 1. Admin login 2. Telecaller registration 3. Update Excel ...