Friday, June 9, 2017

How to Install Apache 2.4 and Configure Virtual Host in Ubuntu 16.04 LTS

Apache: - Apache HTTP Server is most commonly used an open source web server, Apache maintain and developed by the open community of the developers.

Apache provides us wide varieties to run the application written in multiple languages i.e. PHP, Perl, Python, HTM etc.  




Prerequisites: -  
1- One installed Ubuntu 16.04, VM, VPC or Dedicated server.
2- User having sudoers privileges.

Installation: -
SSH to Ubuntu box user with sudoers privileges;

Check Ubuntu Version:

Use command hostnamectl  to know installed version of Linux
root@ip-10-0-1-168:~# hostnamectl
   Static hostname: ip-10-0-1-168
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 389d9e43da834a1ea663f0e6bca2d919
           Boot ID: 65a0542f675f4389ae41dcbccbb3e684
    Virtualization: xen
  Operating System: Ubuntu 16.04.2 LTS
            Kernel: Linux 4.4.0-1017-aws
      Architecture: x86-64
root@ip-10-0-1-168:~#

Step 1: - Check existing installation of Apache
We can check whether our Server already has Apache installed or not using the command below:
root@ip-10-0-1-168:~# dpkg --list apache2
dpkg-query: no packages found matching apache2
root@ip-10-0-1-168:~#
Step 2: - Install Apache 2.4
Use Command below to install Apache 2.4
root@ip-10-0-1-168:~# apt install apache2
Check Installed Apache Version: - 
root@ip-10-0-1-168:~# apache2 -v
Server version: Apache/2.4.18 (Ubuntu)
Server built:   2017-05-05T16:32:00
Check Apache Server Status: -
Using Command below, we can check apache service status
root@ip-10-0-1-168:~# systemctl status apache2.service
● apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: active (running) since Fri 2017-06-09 07:23:28 UTC; 4min 36s ago
     Docs: man:systemd-sysv-generator(8)
    Tasks: 55
   Memory: 6.6M
      CPU: 182ms
   CGroup: /system.slice/apache2.service
           ├─8373 /usr/sbin/apache2 -k start
           ├─8376 /usr/sbin/apache2 -k start
           └─8377 /usr/sbin/apache2 -k start

Jun 09 07:23:27 ip-10-0-1-168 systemd[1]: Starting LSB: Apache2 web server...
Jun 09 07:23:27 ip-10-0-1-168 apache2[8349]:  * Starting Apache httpd web server apache2
Jun 09 07:23:28 ip-10-0-1-168 apache2[8349]:  *
Jun 09 07:23:28 ip-10-0-1-168 systemd[1]: Started LSB: Apache2 web server.
root@ip-10-0-1-168:~#
 Ubuntu Firewall: -
Apache Sever using default port 80. To access the website from outside we need to allow Port 80 in Ubuntu Firewall (UFW).
Check Ubuntu Firewall Status using the command below:
root@ip-10-0-1-168:~# ufw status
Status: inactive
In my case Ubuntu Firewall is inactive, If Ubuntu Firewall is Active we need to allow Port 80 using the command below:
root@ip-10-0-1-168:~# ufw allow 80/tcp
Rule added
Rule added (v6)
root@ip-10-0-1-168:~#
 After adding Port 80 reload Ubuntu Firewall using below command 
root@ip-10-0-1-168:~# ufw reload
Firewall reloaded
 Checked open port status using the command below:
root@ip-10-0-1-168:~# ufw status
Status: active

To                         Action      From
--                         ------      ----
80/tcp                     ALLOW       Anywhere
22/tcp                     ALLOW       Anywhere
80/tcp (v6)                ALLOW       Anywhere (v6)
22/tcp (v6)                ALLOW       Anywhere (v6)

Check Apache server using server's IP address:
 After successful installation of Apache let's check server status:























Apache has been installed Successfully:

Step 3: - Create Virtual Host
 We need Vhost to run multiple websites on a single server-  Let's create a virtual host using the command below:
root@ip-10-0-1-168:~# vi /etc/apache2/sites-available/myvhost.conf
Append following code into this file.
<VirtualHost *:80>
    ServerAdmin amar.singh@outlook.in
    ServerName myvhost.org
    DocumentRoot /var/www/html/myvhost/
    ErrorLog /var/www/html/myvhost/logs/error.log
    CustomLog /var/www/html/myvhost/logs/access.log combined
<Directory /var/www/html/myvhost/>
    Options All
    AllowOverride All
    Require all granted
</Directory>
</VirtualHost> 
Save and Exit from File.

Enable created Virtual host:
root@ip-10-0-1-168:~# a2ensite myvhost.conf
Enabling site myvhost.
To activate the new configuration, you need to run:
service apache2 reload


Reload Apache configuring using the command below:
root@ip-10-0-1-168:~# systemctl reload apache2.service

Validate create Virtual host using server name:










!!!Apache installation and Virtual host creation have done successfully!!!

How to install MySQL: - 
https://linuxhowtoguide.blogspot.in/2017/06/how-to-install-mysql-57-on-ubuntu-1604.html

No comments:

Post a Comment