How to Install Apache on Ubuntu 18.04

Introduction

Apache is an open-source web server that is used to host websites and web applications. It is one of the most popular web servers in the world and is used by many large companies. Installing Apache on Ubuntu 18.04 is a relatively simple process that can be completed in a few steps. In this guide, we will show you how to install Apache on Ubuntu 18.04. We will also provide some basic configuration steps to get your web server up and running.

How to Install Apache on Ubuntu 18.04

1. Update the apt package index:

sudo apt update

2. Install the Apache package:

sudo apt install apache2

3. Check the status of the Apache service to make sure it is running:

sudo systemctl status apache2

4. Adjust the firewall to allow web traffic:

sudo ufw allow ‘Apache’

5. Test that the web server is working properly by visiting your server’s domain name or public IP address in a web browser:

http://your_server_ip_or_domain

You should see the Apache2 Ubuntu Default Page.
[ad_1]

Introduction

This guide will help you install the Apache web server on Ubuntu Linux 18.04.

Apache Web Server is a software package that turns a computer into an HTTP server. That is, it sends web pages – stored as HTML files – to people on the internet who request them. It is open-source software, which means it can be used and modified freely.

how to install apache2 on ubuntu 18.04 bionic beaver

Prerequisites

Tools / Software

  • A command-line utility (Use keyboard shortcut CTRL-ALT-T, or right-click the desktop and left-click Open Terminal)
  • A firewall – the default UFW (Uncomplicated Firewall) in Ubuntu is fine
  • The APT package manager, installed by default on Ubuntu

How to Install Apache on Ubuntu

Before installing new software, it’s a good idea to refresh your local software package database to make sure you are accessing the latest versions. This helps cut down on the time it takes to update after installation, and it also helps prevent zero-day exploits against outdated software.

Open a terminal and type:

sudo apt-get update

Let the package manager finish updating.

Step 1: Install Apache

To install the Apache package on Ubuntu, use the command:

sudo apt-get install apache2

The system prompts for confirmation – do so, and allow the system to complete the installation.

Terminal command to install Apache on Ubuntu.

Step 2: Verify Apache Installation

To verify Apache was installed correctly, open a web browser and type in the address bar:

http://local.server.ip

The web browser should open a page labeled “Apache2 Ubuntu Default Page,” as in the image below:

apache2 the default welcome page on ubuntu

Note: Replace local.server.ip with the IP address of your server. If you are unsure what’s the IP address, run the following terminal command:

hostname -I | awk '{print $1}'

The output will return your server’s IP address.

Step 3: Configure Your Firewall

Although the Apache installation process is complete, there is one more additional step. Configure the default UFW firewall to allow traffic on port 80.

Start by displaying available app profiles on UFW:

sudo ufw show app list

The terminal should respond by listing all available application profiles, as seen in the example below.

Available applications:
  Apache
  Apache Full
  Apache Secure
  OpenSSH

Use the following command to allow normal web traffic on port 80:

sudo ufw allow 'Apache'
Image of how Apache traffic is allowed in Ubuntu terminal.

Verify the changes by checking UFW status:

sudo ufw status
Check UFW status and verify that Apache traffic is allowed.

If you have other applications or services to allow, make sure you configure your firewall to allow traffic. For example, using the sudo ufw allow 'OpenSSH' command will enable secure, encrypted logins over the network.

Note: At this point, your Apache service on Ubuntu is up and running. If you are familiar with Apache, a next common step is setting up Apache virtual hosts.

Apache Configuration

Apache Service Controls

When managing a web server, it’s helpful to have some level of control over the service. You’ll probably find yourself reloading or restarting Apache quite frequently, as you make configuration changes and test them. However, it’s also helpful to be able to stop (and start) the Apache service as needed.

This operation uses the systemctl command, with a series of switches:

Stop Apache:

sudo systemctl stop apache2.service

Start Apache:

sudo systemctl start apache2.service

Restart Apache:

sudo systemctl restart apache2.service

Reload Apache:

sudo systemctl reload apache2.service

Apache Configuration Files, Directories and Modules

Now that you have Apache installed, there are a couple of other things you will need to be aware of to make content available online. Most of all, this means dealing with directories and configuration files.

Directories

After installing, Apache by default creates a document root directory at /var/www/html

Any files that you place into this directory are available to Apache to distribute over the network. Which means, this is the place where you copy web page files you want to publish. This is also where you would want to install content management systems, such as WordPress.

Configuration Files

As mentioned above, website content is stored in the/var/www/html/directory. You can create subdirectories within this location for each different website hosted on your server.

Apache creates log files for any errors it generates in the file /var/log/apache2/error.log.

It also creates access logs for its interactions with clients in the file /var/log/apache2/access.log.

Like many Linux-based applications, Apache functions through the use of configuration files. They are all located in the /etc/apache2/ directory.

Here’s a list of other essential directories:

  • /etc/apache2/apache2.conf – This is the main Apache configuration file and controls everything Apache does on your system. Changes here affect all the websites hosted on this machine.
  • /etc/apache2/ports.conf – The port configuration file. You can customize the ports Apache monitors using this file. By default, Port 80 is configured for http traffic.
  • /etc/apache2/sites-available – Storage for Apache virtual host files. A virtual host is a record of one of the websites hosted on the server.
  • /etc/apache2/sites-enabled – This directory holds websites that are ready to serve clients. The a2ensite command is used on a virtual host file in the sites-available directory to add sites to this location.

There are many directories and configuration files, which are detailed in the Apache Ubuntu documentation. These can be used to add modules to enhance Apache’s functionality, or to store additional configuration information.

Modules

If you intend to work with software modules – applications that expand or enhance the functionality of Apache – you can enable them by using:

sudo a2enmod name_of_module

To disable the module:

sudo a2dismod name_of_module

Glossary

  • UFW – Uncomplicated Firewall, a software application that blocks network traffic (usually for security)
  • SSH – Secure Shell, used for encrypted logins over a network
  • APT – Ubuntu’s default package manager, used for installing and updating software packages
  • GUI – Graphical User Interface – the “point and click” interface of the operating system

Conclusion

This tutorial helped you install Apache on Ubuntu using a set of simple commands. In addition, you now know host to configure basic settings for your installation.

[ad_2]

How to Install Apache on Ubuntu 18.04

Apache is an open-source web server that can be used to serve web pages on the internet. It is one of the most popular web servers in the world, and is commonly used to host websites and web applications. In this guide, we will show you how to install Apache on an Ubuntu 18.04 server.

Prerequisites

Before you begin with this guide, you should have a non-root user with sudo privileges configured on your server. You can learn how to configure a regular user account by following our Ubuntu 18.04 initial server setup guide.

Step 1 — Installing Apache

The Apache web server is available within Ubuntu’s default software repositories, so we can use the apt package manager to install it. We will also install the libapache2-mod-php package which will enable us to serve PHP content with Apache.

We can install both of these packages by typing:

sudo apt update
sudo apt install apache2 libapache2-mod-php

Once the installation is complete, we can start the Apache service by typing:

sudo systemctl start apache2

We can check the status of the service to make sure it is running by typing:

sudo systemctl status apache2

The output should look something like this:

● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2018-04-16 11:03:44 UTC; 1min 32s ago
 Main PID: 2887 (apache2)
    Tasks: 55 (limit: 1153)
   CGroup: /system.slice/apache2.service
           ├─2887 /usr/sbin/apache2 -k start
           ├─2889 /usr/sbin/apache2 -k start
           ├─2890 /usr/sbin/apache2 -k start
           ├─2891 /usr/sbin/apache2 -k start
           ├─2892 /usr/sbin/apache2 -k start
           └─2893 /usr/sbin/apache2 -k start

We can also enable the Apache service to start on boot by typing:

sudo systemctl enable apache2

Step 2 — Adjusting the Firewall

If you have the UFW firewall enabled, you will need to adjust the firewall rules to allow access to the Apache service. We can open the default port for the Apache web server, which is port 80, by typing:

sudo ufw allow in "Apache Full"

You can verify the change by typing:

sudo ufw status

The output should look something like this:

Status: active

To                         Action      From
--                         ------      ----
Apache Full                ALLOW       Anywhere
Apache Full (v6)           ALLOW       Anywhere (v6)

Step 3 — Testing Apache

At this point, Apache should be installed and running on your Ubuntu 18.04 server. We can test this by accessing the web server through a web browser. To do this, you will need to know your server’s public IP address. You can find this by typing:

ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

Once you have your server’s public IP address, you can type it into your web browser’s address bar. You should see the Apache 2 Ubuntu Default Page, which looks like this:

Apache 2 Ubuntu Default Page

If you see this page, then your web server is now correctly installed and accessible through your web browser.

Conclusion

In this guide, we have shown you how to install Apache on an Ubuntu 18.04 server. We have also shown you how to adjust the firewall to allow external access to the web server, and how to test the installation.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

GSTIN is 03EGRPS4248R1ZD.

Contact
Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00