Menu

Log in

Sign up

From beginner to master of web design, coding, infrastructure operation, business development and marketing

  • COURSES
  • HTML & CSS Introduction
  • HTML & CSS Coding with AI
  • Linux Introduction
  • Docker Basics
  • Git & GitHub Introduction
  • JavaScript Coding with AI
  • Django Introduction
  • AWS Basics
  • Figma Introduction
  • SEO Tutorial for Beginners
  • SEO with AI
  • OTHERS
  • About
  • Terms of Service
  • Privacy Policy

© 2024 D-Libro. All Rights Reserved

Linux IntroductionChapter 8. Process Management

Launch Apache Web Server

Launch Apache Web Server

Launching Apache Web Server on Linux

Launching a web server yourself gives you a better idea about Linux processes and services. In this section, we'll explain how to launch an Apache web server on Linux using an AWS Lightsail Ubuntu instance and host web pages using the server.

Overview of launching Apache web server

There are four major steps to launch Apache web server and host website files.

  • Step 1. Install Apache
  • Step 2. Enable and Start Apache
  • Step 3. Place Website files
  • Step 4. Set up Firewall

Step 1. Install Apache

To install Apache, use a package manager. In this case, we use apt. To maintain proper dependencies and install the right version of the program, run the "apt update" command first before setting up the Apache web server. This process may take a few minutes.

Command Line - INPUT
sudo apt update
sudo apt -y install apache2

Step 2. Enable and Start Apache

Once Apache is installed, you can enable it using the systemctl enable command. To start Apache right away, use the --now option as shown in the command below.

Command Line - INPUT
sudo systemctl enable --now apache2
Command Line - RESPONSE
Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable apache2

Using the systemctl status command, you can confirm that the Apache web server is enabled and running.

Command Line - INPUT
systemctl status apache2
Command Line - RESPONSE
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2023-02-28 07:19:11 UTC; 8min ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 3507 (apache2)
      Tasks: 55 (limit: 560)
     Memory: 5.1M
     CGroup: /system.slice/apache2.service
             ├─3507 /usr/sbin/apache2 -k start
             ├─3509 /usr/sbin/apache2 -k start
             └─3510 /usr/sbin/apache2 -k start

You can confirm that the Apache server is running using the IP address of the server. The IP address of the server on the AWS Lightsail instance can be found on the Lightsail instance page.

IP address of the AWS Lightsail instance

Copy the IP address and paste it into the browser. You can see the Apache2 Ubuntu Default Page as shown below. If you cannot connect, check the firewall setting. For now, you can disable UFW by running ufw disable.

Apache2 Ubuntu Default Page

This document is the index.html file found in /var/www/html, which is a directory used to store website documents that will be hosted by the Apache web server.
After moving to the directory, run the ls command. You can find the index.html file in the directory.

Command Line - INPUT
cd /var/www/html
ls
Command Line - RESPONSE
index.html

Step 3. Place Website files

To host your website on the server, place your website files in the /var/www/html directory and replace the existing index.html file with your index.html file.

For practice purposes, rename the existing index.html file as index_original.html first, and create a new index.html file like in the example below.

Command Line - INPUT
sudo mv index.html index_original.html
sudo vim index.html

index.html file

<!DOCTYPE html>
<html>
<head>
   <title> Test Page</title>
</head>
<body>  
   <h1> TEST TEST TEST</h1>
</body> 
</html>

If you type the IP address in the browser, you'll see that your new html file was successfully deployed.

Apache2 Server Test Results

Step 4. Set Up Firewall

Lastly, for security purposes, set up the firewall using the UFW tool. First, enable UFW using the ufw enable command.

Command Line - INPUT
sudo ufw enable
Command Line - RESPONSE
Firewall is active and enabled on system startup

And, allow port 22 for ssh and port 80 for HTTP. Then, check the firewall status.

Command Line - INPUT
sudo ufw allow 22
sudo ufw allow 80
sudo ufw status
Command Line - RESPONSE
Status: active

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

You can also learn this topic offline. Click AmazonKindle.

More Topics to Explore

Collaborating on Git & Git Hub - Branch

Collaborating on Git & Git Hub – Branch

Displaying Related Model Data in Django Templates

Template with Model Relations

Git & GitHub Project Setup Scenarios

Three Cases in Git & GitHub Project Setup

Creating and Modifying Files with touch Command

touch (Create File)

Django Models and Databases Guide

Chapter 3. Django Models and Databases

Collaborating on Git & Git Hub - Branch

Collaborating on Git & Git Hub – Branch

Displaying Related Model Data in Django Templates

Template with Model Relations

Git & GitHub Project Setup Scenarios

Three Cases in Git & GitHub Project Setup

Creating and Modifying Files with touch Command

touch (Create File)

Django Models and Databases Guide

Chapter 3. Django Models and Databases

Tags:

Web Server

Apache

Linux Introduction
Course Content

Chapter 1. Linux Basics

What Is OS?

CUI and GUI

Linux Distributions

Package Manager

Kernel and Shell

Current Working Directory

Linux Directory Structure

Absolute Path and Relative Path (Linux OS)

Linux Command Syntax

Special Characters and Escape Character

Chapter 2. Linux Key Commands

Setting Up Linux Environment on AWS

pwd (Print Working Directory)

cd (Change Directory)

ls (List Contents of Directory)

mkdir (Make Directory)

rmdir (Remove Directory)

touch (Create File)

rm (Remove File)

mv (Move File and Directory)

cp (Copy File and Directory)

cat (Display File Content)

sort (Sort File Contents)

grep (Global Regular Expression Print)

Regular Expression

find (Find File and Directory)

Wildcard

ln (Create Link to File and Directory)

Chapter 3. Vim Editor

What Is Vim and How to Launch It?

Normal, Insert and Visual Mode

Normal Mode (1) – Move Cursor

Normal Mode (2) – Delete

Normal Mode (3) – Copy and Paste

Normal Mode (4) – Undo and Redo

Normal Mode (5) – Search Phrase

Normal Mode (6) – Replace Phrase

Normal Mode (7) – Save and Exit

Insert Mode

Visual Mode

Chapter 4. User, Group and Permission

What Are User, Group And Permission in Linux?

Permission (Access Mode) by Owner Status

Superuser (Root User) vs. Normal User

sudo (Run Command with Superuser Privileges)

su (Switch User)

useradd (Add User)

passwd (Set Password)

userdel (Delete User)

Group – Primary Group and Secondary Group

groupadd (Add Group)

usermod (Modify User Account Information)

gpasswd (Add and Delete Users to Group)

groupdel (Delete Group)

chown (Change Owner of File and Directory)

chgrp (Change Group of File and Directory)

chmod (Change Access Mode)

chmod Command with Numbers

w and who (Check Current User Login Status)

id and groups (Check User ID and Group)

getent (Display User and Group Data)

Chapter 5. Redirection, Pipe and Shell Script

Standard Input Output and Redirection

Pipe (Combine Commands)

less (Display Content with Pager)

tr (Replace Characters)

cut (Extract Data Sections)

uniq (Extract Unique Data Lines)

Shell Script

echo (Echo input)

read (Read and Store Input)

Shell Variable and Environmental Variable

source (Execute Shell Script and Refresh Environmental Variables)

Chapter 6. Linux Commands for Command Management

history (Check Command History)

alias (Create Command Shortcuts)

man (Display Manual)

type, which and whereis (Display Command Information)

Package Manager Command

tree (Display Directory Tree)

Chapter 7. SSH Remote Connection

SSH (Secure Shell)

Locate .ssh Directory

SSH Remote Login (1) – Use Key Pair Generated by Server

SSH Remote Login (2) – Use Key Pair Generated by Client

SSH Config File

SSH Remote Login with Visual Studio Code

SCP (Secure Copy Protocol)

SCP with SSH Config File

SFTP (Secure File Transfer Protocol)

Other File Transfer Commands

Chapter 8. Linux Process Management

Process and Job

Foreground and Background Jobs

jobs and ps (Display Jobs and Processes)

Signals

Create, Stop and Terminate Jobs

Daemon Processes

What Is Service on Linux?

Systemd

Unit File

Systemctl Sub-Commands

Create Custom Unit and Start at Boot

Firewall

UFW (Uncomplicated Firewall)

Web Server

Launch Apache Web Server

Chapter 1. Linux Basics

What Is OS?

CUI and GUI

Linux Distributions

Package Manager

Kernel and Shell

Current Working Directory

Linux Directory Structure

Absolute Path and Relative Path (Linux OS)

Linux Command Syntax

Special Characters and Escape Character

Chapter 2. Linux Key Commands

Setting Up Linux Environment on AWS

pwd (Print Working Directory)

cd (Change Directory)

ls (List Contents of Directory)

mkdir (Make Directory)

rmdir (Remove Directory)

touch (Create File)

rm (Remove File)

mv (Move File and Directory)

cp (Copy File and Directory)

cat (Display File Content)

sort (Sort File Contents)

grep (Global Regular Expression Print)

Regular Expression

find (Find File and Directory)

Wildcard

ln (Create Link to File and Directory)

Chapter 3. Vim Editor

What Is Vim and How to Launch It?

Normal, Insert and Visual Mode

Normal Mode (1) – Move Cursor

Normal Mode (2) – Delete

Normal Mode (3) – Copy and Paste

Normal Mode (4) – Undo and Redo

Normal Mode (5) – Search Phrase

Normal Mode (6) – Replace Phrase

Normal Mode (7) – Save and Exit

Insert Mode

Visual Mode

Chapter 4. User, Group and Permission

What Are User, Group And Permission in Linux?

Permission (Access Mode) by Owner Status

Superuser (Root User) vs. Normal User

sudo (Run Command with Superuser Privileges)

su (Switch User)

useradd (Add User)

passwd (Set Password)

userdel (Delete User)

Group – Primary Group and Secondary Group

groupadd (Add Group)

usermod (Modify User Account Information)

gpasswd (Add and Delete Users to Group)

groupdel (Delete Group)

chown (Change Owner of File and Directory)

chgrp (Change Group of File and Directory)

chmod (Change Access Mode)

chmod Command with Numbers

w and who (Check Current User Login Status)

id and groups (Check User ID and Group)

getent (Display User and Group Data)

Chapter 5. Redirection, Pipe and Shell Script

Standard Input Output and Redirection

Pipe (Combine Commands)

less (Display Content with Pager)

tr (Replace Characters)

cut (Extract Data Sections)

uniq (Extract Unique Data Lines)

Shell Script

echo (Echo input)

read (Read and Store Input)

Shell Variable and Environmental Variable

source (Execute Shell Script and Refresh Environmental Variables)

Chapter 6. Linux Commands for Command Management

history (Check Command History)

alias (Create Command Shortcuts)

man (Display Manual)

type, which and whereis (Display Command Information)

Package Manager Command

tree (Display Directory Tree)

Chapter 7. SSH Remote Connection

SSH (Secure Shell)

Locate .ssh Directory

SSH Remote Login (1) – Use Key Pair Generated by Server

SSH Remote Login (2) – Use Key Pair Generated by Client

SSH Config File

SSH Remote Login with Visual Studio Code

SCP (Secure Copy Protocol)

SCP with SSH Config File

SFTP (Secure File Transfer Protocol)

Other File Transfer Commands

Chapter 8. Linux Process Management

Process and Job

Foreground and Background Jobs

jobs and ps (Display Jobs and Processes)

Signals

Create, Stop and Terminate Jobs

Daemon Processes

What Is Service on Linux?

Systemd

Unit File

Systemctl Sub-Commands

Create Custom Unit and Start at Boot

Firewall

UFW (Uncomplicated Firewall)

Web Server

Launch Apache Web Server