How to Install Apache on Ubuntu 18.04 Linux

October 23, 2019

Comments

Adsense

Adsense

Adsense

Adsense

When we are thinking about web server the first name is coming Apache HTTP server, it is most popular in the world for hosting any type of web applications or websites. The most important thing about Apache web server is, it is free and open-source web server and providing a powerful feature for your web application, including support of cross-platform.
 
In this tutorial, we will explain the process of installing the Apache webserver on Ubuntu 18.04 Operating System.

Prerequisites

To perform Apache web server installation on your Ubuntu 18.04 system, you should have user access to login on system and need sudo privileges to execute administrative commands to install applications.

Install Apache

The apache web server packages are inbuilt in Ubuntu repository packages which we can easily install using “apt” command. The only thing is to know the Apache HTTP server’s service is known as “apache2” in Ubuntu Operating System.
 
To install Apache2 package, first, need to update Ubuntu package index and install apache2 using the following command:
$ sudo apt update
$ sudo apt install apache2

Now, the apache web server is installed and automatically started on your Ubuntu machine. You can check the apache web server’s service status using the following command:

$ sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
           `-apache2-systemd.conf
   Active: active (running) since Sun 2019-06-24 02:17:57 PDT; 2min 41s ago
 Main PID: 4243 (apache2)
    Tasks: 55 (limit: 2321)
   CGroup: /system.slice/apache2.service
           |-4243 /usr/sbin/apache2 -k start
           |-4244 /usr/sbin/apache2 -k start
           `-4245 /usr/sbin/apache2 -k start

Configure the Firewall for Apache wen server on Ubuntu 18.04

Nowadays, every system we protesting with Firewall to secure system and services. If Firewall also protests your Ubuntu system, you need to open HTTP (80) and HTTPS (443) port to access the webserver.
 
Assuming your system is secured using UFW firewall, as most of the Ubuntu machine using UFW firewall, you can open the Apache ports using the following command:
$ sudo ufw allow 'Apache Full'

You can verify the port is open or not on UFW firewall using below command:

$ sudo ufw status
Status: active
To                         Action      From
--                         ------      ----
22/tcp                     ALLOW       Anywhere
Apache Full                ALLOW       Anywhere
22/tcp (v6)                ALLOW       Anywhere (v6)
Apache Full (v6)           ALLOW       Anywhere (v6)

Verify Apache Installation

To verify apache web server installed adequately and everything working as per the instructions, open the web browser and open your web server by typing your configured domain or IP for this Ubuntu server like “http://<your_domain_or_IP>.
 

If everything is working and apache webserver running fine, you will get the default Ubuntu 18.04 Apache2 welcome page as shown below:

This page includes some of the necessary information about apache2 web server, configuration file, directory locations and helper scripts.

Apache Configuration File’s Structure

The Apache2 configuration file’s default location is “/etc/apache2/” directory.
 
The main Apache2 web server configuration file is “/etc/apache2/apache2.conf”.
 
The Apache listener ports configuration file located at “/etc/apache2/ports.conf”.
 
The virtual host files configured on Apache webserver stored in the “/etc/apace2/sites-available/” directory. But the configuration file found in this directory is not used by apache unless they linked to the “/etc/apache2/sites-enabled/” directory.
 
To activate the virtual host file and use it with apache configuration need to create a symlink file from “sites-available” to sites-enabled”. In apache, it is straightforward which can do by using the “a2ensite” command and similarly deactivate the virtual host file or remove symlink file use the command “a2dissite”.
 
To configure a virtual host file, it is good to follow the standard naming convention. For example, you are configuring virtual host for your domain “testsite.com” then you should keep the virtual host configuration name as “/etc/apache2/sites-available/testsite.com.conf”.
 
The apache web server’s module configuration files stored in the “/etc/apache2/mods-available/” directory. Similar to “sites-available”, “mods-available” files are usable only when it enabled by creating a symlink to the “/etc/apache2/mods-enabled/” directory using “a2enmod” command, and it disabled by using “a2dismod” command.
 
The global configuration files for apache web servers stored in the “/etc/apache2/conf-available/” directory. Similar to “sites-available” and “mods-available”, “conf-available” files are usable only when it enabled by creating a symlink to the “/etc/apache2/conf-enabled/” directory using “a2enconf” command, and it disabled by using “a2disconf” command.
 
To troubleshoot or debug the issue with the apache web server, use the log file for apache server and virtual host. The log file for apache located at “/var/log/apache2/access.log” and “/var/log/apache2/error.log”. To make it easy to troubleshoot an issue with different virtual host need to create different access and error log for each virtual host.
 
There is no location boundary to create document root directory, you can create at any location but as per suggestion, the most common location for webroot directory is:
  • /var/www/<site_Name>
  • /var/www/html/<Site_Name>
  • /opt/<site_Name>
  • /home/<user_name>/<Site_Name>

Conclusion

You have learned to install Apache web server on your Ubuntu 18.04 server or system. Now your system is ready to deploy a web application using Apache virtual host or use Apache as a web proxy server for your application.

Do you have any doubt, questions or feedback? Feel free to leave a comment.
Satish Kumar

Satish Kumar

I am Satish Kumar, Founder of LinuxConcept. Linux and F.O.S.S enthusiast, love to work on open source platform and technologies.

Adsense

Adsense

Adsense

Adsense

Adsense

Adsense

Adsense

Adsense

Adsense

Related Posts

Delete a user account from Ubuntu Desktop or Server

If you no longer need a user account, it is good idea to delete that account.Getting ready You will need super user or root privileges to delete a group from the Ubuntu server.How to do it... Follow these steps to delete the user account:Enter the following command to...

Creating a group on Ubuntu Desktop or Server

Group is a way to organize and administer user accounts in Linux. Groups are used to collectively assign rights and permissions to multiple user accounts.Getting ready You will need super user or root privileges to add a group to the Ubuntu server.How to do it......

Creating a user account on Ubuntu desktop or server

Suppose you have already installed the Ubuntu desktop or server. In that case, it means you have already created a default user on your system, even on the cloud also Ubuntu is installed with preconfigured default user account. You can do all administrative tasks...

0 Comments

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

17 + 3 =

News & Updates

Join Our Newsletter

Adsense

Adsense

Adsense

Adsense