• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

SMASHING LAB

GUIDES | LINUX | GEEKY STUFF

  • Nginx
  • Linux
  • Guide
  • Ubuntu
  • WordPress
  • Drones, My Hobby

Guide How to Install Apache in Ubuntu 18.04

By Imran Yousaf

Apache HTTP Server is the most popular web server in the world. This is a free, open-source, and cross-platform HTTP server that provides advanced features that can be expanded with a variety of modules.

The Apache HTTP Server project is an effort to develop and maintain an open-source HTTP server for modern operating systems including UNIX and Windows. The aim of this project is to provide a secure, efficient and expandable server that provides HTTP services that are in line with current HTTP standards.

Apache HTTP Server (“httpd”) was launched in 1995 and has been the most popular web server on the Internet since April 1996. He celebrated his 20th birthday as a project in February 2015.

This guide explains how to install and manage an Apache web server on Ubuntu 18.04.

Requirements

Before starting with this guide, make sure you are logged in as a user with sudo privileges. → How to create a Sudo User and Sudo Group on Ubuntu .

Install Apache

Apache is available in Ubuntu’s default repository so we can easily install it using a package management tool apt. On Ubuntu and Debian systems, the Apache package and its service are called apache2.

First, update the package index and then install the package apache2with the following command:

sudo apt update
sudo apt install apache2

And that’s it, Apache is installed and automatically started. You can check the status of the Apache service with the following command:

sudo systemctl status apache2

1
2
3
4
5
6
7
8
9
10
11
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 2018-06-24 02:17:57 PDT; 2min 41s ago
Main PID: 3143 (apache2)
    Tasks: 55 (limit: 2321)
   CGroup: /system.slice/apache2.service
           |-3143 /usr/sbin/apache2 -k start
           |-3144 /usr/sbin/apache2 -k start
           `-3145 /usr/sbin/apache2 -k start

Adjust Firewall

If your Ubuntu server is protected by a firewall, you must open HTTP ( 80) and HTTPS ( 443) ports .

Assuming you are using it UFWto manage your firewall, you can open the required ports with the following command:

sudo ufw allow 'Apache Full'

You can verify changes by:

sudo ufw status

1
2
3
4
5
6
7
8
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)

Verifying the Apache Installation

To verify that everything is functioning correctly, open your web browser, type the IP address of your server http://YOUR_IP_OR_DOMAIN/and you will see the default Apache 18.04 Apache welcome page as shown in the image below:

This page includes some basic information about Apache configuration files, helper scripts, and directory locations.

Apache Configuration File Structure and Best Practices

  • All Apache configuration files are located in the directory /etc/apache2.
  • The main Apache configuration file is /etc/apache2/apache2.conf.
  • The ports that Apache will listen to are specified in /etc/apache2/ports.conf.
  • Apache Virtual Hosts files are stored in a directory /etc/apache2/sites-available. The configuration files found in this directory are not used by Apache unless they are linked to the directory /etc/apache2/sites-enabled.
  • To enable virtual hosts, you need to create a symlink by using commands a2ensitefrom the configuration file found in the directory sites-availableto the directory sites-enabled. To disable the virtual host use the command a2dissite.
  • It is a good idea to follow the standard naming convention. For example, if your domain name is mydomain.comthen the virtual host configuration file must be named /etc/apache2/sites-available/mydomain.com.conf.
  • The configuration file responsible for loading various Apache modules is in the directory /etc/apache2/mods-available/. Configuration in the directory mod-availablecan be activated by creating a symlink to the directory /etc/apache2/mods-enable/with the command a2enconfand deactivated with the command a2disconf.
  • Files containing global configuration fragments are stored in the directory /etc/apache2/conf-available/. Files in the directory conf-availablecan be activated by creating a symlink to /etc/apache2/conf-enabled/with the command a2enconfand deactivated with the command a2disconf.
  • The Apache log files (access.log and error.log) are located in the directory /var/log/apache/. It is recommended to have different access and error log files for each vhost.
  • You can set the root directory of your domain’s document to the location you want. The most common locations for webroots include:
    • /home/<user_name>/<site_name>
    • /var/www/<site_name>
    • /var/www/html/<site_name>
    • /opt/<site_name>

Conclusion

You have successfully installed Apache on your Ubuntu 18.04 linux server. You are now ready to start deploying your application and use Apache as a web or proxy server.

Some more articles you might also be interested in …

  • Install and Configure Apache on Ubuntu Server
  • Complete Guide: How To Install Ubuntu Server 18.04
  • How to Install LAMP Stack (Linux, Apache, MySQL,…
  • How to Install and Secure phpMyAdmin with Apache on…
  • Install LEMP Stack (Nginx, MariaDB, PHP-FPM) on…
  • How To Dual Boot Linux/Ubuntu and Windows 10…
  • How to Install Brackets on Debian / Ubuntu
  • How to Install and Use Multiple Versions of PHP on…
  • Guide on How to Disable SELinux
  • Compress the Apache Server Output with GZIP
Tweet
Pin
Share
0 Shares

Filed Under: Guide, Ubuntu

Primary Sidebar

  • Twitter
  • Facebook
  • Google+

Recent Posts

  • How to install Nextcloud on CentOS 8
  • How to install Zabbix on openSUSE Leap 15.1
  • How to Easily Configure Your Domain’s Email Account with Gmail?
  • Tails 4.4 OS Released with Tor Browser 9.0.6
  • How to Convert JPG to PDF in Linux

Subscribe to our Newsletter

Useful articles, tips and videos about creating and promoting websites to your mail



* required field


  • Contact Us
  • Privacy Policy
  • About Us

Copyright © 2021. Smashing Lab