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/primeprogrammer.com/


Step 2: Change ownership from root to current user

$ sudo chown -R $USER:$USER /var/www/primeprogrammer.com/

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/primeprogrammer.com/index.html

<html>
 <head>
 <title>www.primeprogrammer.com</title>
 </head>
 <body>
 <h1>Hello, This is a test page for primeprogrammer.com website</h1>
 </body>
</html>

Save & Close file.

Step 5:  Create configuration file for your host (primeprogrammer.com)

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

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.
 #ServerName www.example.com

   ServerAdmin webmaster@primeprogrammer.com
   ServerName primeprogrammer.com
   ServerAlias www.ostechnix1.lan
   DocumentRoot /var/www/primeprogrammer.com

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

Save & Close


Step 6:  Disable default virtual host

$ sudo a2dissite 000-default.conf

Step 7:  Enable your configured virtaul host

$ sudo a2ensite primeprogrammer.com.conf

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 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
Syntax OK


Step 9: Configure defined site to hosts file

$ sudo vi /etc/hosts

[.....]
127.0.0.1     primeprogrammer.com
[.....] 


Step 10: Restart your apache2 server

$ sudo systemctl restart apache2

That's it.

Finally, open your installed browser and hit below url:

http://primeprogrammer.com

Other Service also provide

Let me know if you have any query.

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